Created
March 2, 2021 16:09
-
-
Save xpqz/f7990c11cdb1a7ee4856bbeb2a0f0dfc to your computer and use it in GitHub Desktop.
Example of unit testing in Dyalog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:Namespace test | |
⍝ Unit tests for the Dict class | |
assert←{⍺←'assertion failure' ⋄ 0∊⍵:⍺ ⎕signal 8 ⋄ shy←0} | |
∇ run | |
⍎¨'test_.+'⎕S'&'⎕NL ¯3 | |
∇ | |
∇ show name | |
⎕←name,((30-≢name)/'.'),'[OK]' | |
∇ | |
∇ test_constructor ;z | |
z←⎕NEW #.dict.Dict (('APL' 'Rocks!')(42 'Bob')) | |
assert z['Rocks!' 'APL' 'APL'] ≡ 'Bob' 42 42 | |
show 'constructor' | |
∇ | |
∇ test_update1 ;z | |
z←⎕NEW #.dict.Dict (('APL' 'Rocks!')(42 'Bob')) | |
z[⊂'Rocks!'] ← ⊂'Eric' | |
assert z._keys ≡ 'APL' 'Rocks!' | |
assert z._values ≡ 42 'Eric' | |
show 'update1' | |
∇ | |
∇ test_upsert ;z | |
z←⎕NEW #.dict.Dict (('APL' 'Rocks!')(42 'Bob')) | |
z['Rocks!' 'NewKey'] ← 'Eric' 'NewVal' | |
assert z._keys ≡ 'APL' 'Rocks!' 'NewKey' | |
assert z._values ≡ 42 'Eric' 'NewVal' | |
show 'upsert' | |
∇ | |
∇ test_add ;z | |
z←⎕NEW #.dict.Dict (('APL' 'Rocks!')(42 'Bob')) | |
z[⊂'NewKey'] ← ⊂'NewVal' | |
assert z._keys ≡ 'APL' 'Rocks!' 'NewKey' | |
assert z._values ≡ 42 'Bob' 'NewVal' | |
show 'add' | |
∇ | |
:EndNamespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment