aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-10 15:15:38 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-10 15:15:38 -0400
commit8d3d5913129a8ede381462d5ad5e98f9c789e5c8 (patch)
tree074e1fd4489710af0810e2a901106a7161467021 /test
parentcb6cebf12e2124503f0551bc1bf6b44f68d86746 (diff)
Add Sets to the language
Diffstat (limited to 'test')
-rw-r--r--test/sets.tm36
-rw-r--r--test/tables.tm24
2 files changed, 60 insertions, 0 deletions
diff --git a/test/sets.tm b/test/sets.tm
new file mode 100644
index 00000000..bfec068e
--- /dev/null
+++ b/test/sets.tm
@@ -0,0 +1,36 @@
+
+func main():
+ >> t1 := {10, 20, 30, 10}
+ = {10, 20, 30}
+ >> t1:has(10)
+ = yes
+ >> t1:has(-999)
+ = no
+
+ >> t2 := {30, 40}
+
+ >> t1:with(t2)
+ >> {10, 20, 30, 40}
+
+ >> t1:without(t2)
+ >> {10, 20}
+
+ >> t1:overlap(t2)
+ >> {30}
+
+
+ >> {1,2}:is_subset_of({2,3})
+ = no
+ >> {1,2}:is_subset_of({1,2,3})
+ = yes
+ >> {1,2}:is_subset_of({1,2})
+ = yes
+ >> {1,2}:is_subset_of({1,2}, strict=yes)
+ = no
+
+ >> t1:add_all(t2)
+ >> t1
+ = {10, 20, 30, 40}
+ >> t1:remove_all(t2)
+ >> t1
+ = {10, 20}
diff --git a/test/tables.tm b/test/tables.tm
index 132e4301..6dbc1b78 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -61,3 +61,27 @@ func main():
>> t3:remove(3)
>> t3
= {1:10, 2:20}
+
+ do:
+ >> plain := {1:10, 2:20, 3:30}
+ >> plain:get(2, -999)
+ = 20
+ >> plain:get(456, -999)
+ = -999
+ >> plain:has(2)
+ = yes
+ >> plain:has(456)
+ = no
+
+ >> fallback := {4:40; fallback=plain}
+ >> fallback:has(1)
+ = yes
+ >> fallback:get(1, -999)
+ = 10
+
+ >> default := {5:50; default=0}
+ >> default:has(28273)
+ = yes
+ >> default:get(28273, -999)
+ = 0
+