12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | macro check(msg, _actual,_expected)
actual := _actual
expected := _expected
if actual == expected
say "Verified $msg: $actual"
else
fail "Expected $msg to be $expected but got $actual"
def test_equal_items()
a := ["A","B","C"]
a_prefix := ["A","B"]
b := ["A","B","C"]
x := ["X","Y","Z"]
check "a.equal_items(a)" a.equal_items(a) yes
check "a_prefix.equal_items(a)" a_prefix.equal_items(a) no
check "a.equal_items(a_prefix)" a.equal_items(a_prefix) no
check "a.equal_items(b)" a.equal_items(b) yes
check "a.equal_items(x)" a.equal_items(x) no
def test_copy()
a := ["a","b","c"]
b := a.copy()
check "$a.copy()" "$a" "$b"
a.insert("XXX")
check "original after append" "$a" "[a, b, c, XXX]"
check "copy after append" "$b" "[a, b, c]"
def test_insert()
a := ["a","b","c","d","e"]
a.insert("x", 3)
check "a.insert(x, 3)" "$a" "[a, b, x, c, d, e]"
a.insert("y", at=3)
check "a.insert(y, at=3)" "$a" "[a, b, y, x, c, d, e]"
a.insert("z", #a+1)
check "a.insert(z, #a+1)" "$a" "[a, b, y, x, c, d, e, z]"
a.insert("w")
check "a.insert(w)" "$a" "[a, b, y, x, c, d, e, z, w]"
def test_insert_all()
a := ["a","b","c"]
x := ["x","y","z"]
a.insert_all(x)
check "a.insert_all(x)" "a:$a x:$x" "a:[a, b, c, x, y, z] x:[x, y, z]"
a := ["a","b","c"]
x := ["x","y","z"]
a.insert_all(x, at=2)
check "a.insert_all(x, at=2)" "a:$a x:$x" "a:[a, x, y, z, b, c] x:[x, y, z]"
def main()
test_equal_items()
test_copy()
test_insert()
test_insert_all()
|