Skip to content

Instantly share code, notes, and snippets.

@xpqz
Created March 2, 2021 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpqz/f7990c11cdb1a7ee4856bbeb2a0f0dfc to your computer and use it in GitHub Desktop.
Save xpqz/f7990c11cdb1a7ee4856bbeb2a0f0dfc to your computer and use it in GitHub Desktop.
Example of unit testing in Dyalog
: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