summary refs log tree commit diff
path: root/lib/table.test.fnl
diff options
context:
space:
mode:
authordozens2024-06-20 09:17:06 -0600
committerdozens2024-06-20 09:17:06 -0600
commitc7b2c982004e350f5e3032321baadfc9021b6bad (patch)
tree3f8883c94bed5a1f847cf60cb11207ca53946c67 /lib/table.test.fnl
parentce09973e7cacccdc779f91b8e6e48a520b9f9f4d (diff)
🗄️ big tidy up
- isolate core game logic and move it to src/game.fnl
- main.fnl should be just the ui now
- move all table funcs into lib/table
- move all (1) string funcs into lib/string
- move all game funcs into lib/game/
Diffstat (limited to 'lib/table.test.fnl')
-rw-r--r--lib/table.test.fnl80
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/table.test.fnl b/lib/table.test.fnl
new file mode 100644
index 0000000..c004d3f
--- /dev/null
+++ b/lib/table.test.fnl
@@ -0,0 +1,80 @@
+(let [{: contains
+       : flip
+       : head
+       : keys
+       : slice
+       : tail
+       } (require :lib.table)
+      {: describe
+       : test-end} (require :lib.test)]
+
+(describe "# TABLE" (fn []
+  (describe "contains()" (fn [t]
+    (t {:given "a list and an element it contains"
+        :should "returns true"
+        :expected true
+        :actual (contains [:apple :orange :pear] :apple)})
+    (t {:given "a list and an element it does not contain"
+        :should "returns false"
+        :expected false
+        :actual (contains [:apple :orange :pear] :gorilla)})))
+
+  (describe "flip()" (fn [t]
+    (let [input {:apple "red" :banana "yellow"}
+          expected {:red "apple" :yellow "banana"} ]
+      (t {:given "a table"
+          :should "flip that table!"
+          : expected
+          :actual (flip input)}))))
+
+  (describe "head()" (fn [t]
+    (t {:given "a list of elements"
+        :should "returns the first element of a list"
+        :expected :apple
+        :actual  (head [:apple :orange :pear])})
+    (t {:given "an empty list"
+        :should "returns an empty list"
+        :expected 0
+        :actual (length (head []))})))
+
+  (describe "keys()" (fn [t]
+    (let [input {:apple :red :banana :yellow}
+          actual (keys input)
+          sorted (table.sort actual) ;; SIDE EFFECT!!
+          ]
+      (t {:given "a table"
+          :should "returns a list of keys"
+          :expected [:apple :banana]
+          : actual}))))
+
+
+  (describe "slice()" (fn [t]
+    (t (let [t [:apple :orange :pear :banana :strawberry] ]
+        {:given "a list of elements and a start"
+         :should "return the list starting at start"
+         :expected [:orange :pear :banana :strawberry]
+         :actual  (slice t 2)}))
+    (t (let [t [:apple :orange :pear :banana :strawberry] ]
+        {:given "a list of elements and a start and a stop"
+         :should "return the items between the two"
+         :expected [:orange :pear]
+         :actual  (slice t 2 3)}))))
+
+
+  (describe "tail()" (fn [t]
+    (t {:given "a list"
+        :should "return it minus the head"
+        :expected [:apple :pear]
+        :actual (tail [:orange :apple :pear])
+        })
+    (t {:given "a single item list"
+        :should "return empty list"
+        :expected []
+        :actual (tail [:orange])
+        })
+    (t {:given "an empty list"
+        :should "return empty list"
+        :expected []
+        :actual (tail [])
+        })))
+ (test-end))))