summaryrefslogtreecommitdiff
path: root/lib/game/mill.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/game/mill.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/game/mill.test.fnl')
-rw-r--r--lib/game/mill.test.fnl123
1 files changed, 123 insertions, 0 deletions
diff --git a/lib/game/mill.test.fnl b/lib/game/mill.test.fnl
new file mode 100644
index 0000000..604c759
--- /dev/null
+++ b/lib/game/mill.test.fnl
@@ -0,0 +1,123 @@
+(let [{: describe
+ : test-end} (require :lib.test)
+ {: mill-at?
+ : get-candidates
+ : move-mills
+ : candidate-moves
+ : any
+ } (require :lib.game.mill)
+ {: mills } (require :lib.constants)
+ with-mills (partial mill-at? mills)]
+
+ (describe "# MILL" (fn []
+ (describe "get-candidates()" (fn [t]
+ (t
+ (let [move 3
+ expected [[1 2 3] [3 15 24]]
+ moves [ 1 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ] ]
+ {:given (string.format "a move of %d" move)
+ :should "return [[1 2 3] [3 15 24]]"
+ : expected
+ :actual (get-candidates mills move)
+ }))
+ (t
+ (let [move 1
+ expected [[1 2 3] [1 10 22]]
+ moves [ 0 0 0 ] ]
+ {:given (string.format "a move of %d" move)
+ :should "return [[1 2 3] [1 10 22]]"
+ : expected
+ :actual (get-candidates mills move) }))
+ (t
+ (let [move 1
+ moves [2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
+ expected [[1 2 3] [1 10 22]]
+ ]
+ {:given (string.format "a move of %d" move)
+ :should "still return [[1 2 3] [1 10 22]]"
+ : expected
+ :actual (get-candidates mills move) }))))
+
+ (describe "any()" (fn [t]
+ (t {:given "a table of false false true"
+ :should "return true"
+ :expected true
+ :actual (any [false false true]) })
+ (t {:given "a table of true false"
+ :should "return true"
+ :expected true
+ :actual (any [true false]) })
+ (t {:given "a single false"
+ :should "return false"
+ :expected false
+ :actual (any [false]) })
+ (t {:given "a single true"
+ :should "return true"
+ :expected true
+ :actual (any [true]) })))
+
+ (describe "move-mills()" (fn [t]
+ (t
+ (let [moves [[1 1 1] [0 2 2]] ]
+ {:given "a list of moves"
+ :should "turn them into true/false if they are mills"
+ :expected [true false]
+ :actual (move-mills moves) }))
+ (t
+ (let [moves [[0 1 1] [0 2 2]] ]
+ {:given "no mills"
+ :should "should return false"
+ :expected [false false]
+ :actual (move-mills moves) }))
+ (t
+ (let [moves [[2 2 2] [2 0 0]] ]
+ {:given "mill, no mill"
+ :should "should return true false"
+ :expected [true false]
+ :actual (move-mills moves) }))))
+
+ (describe "candidate-moves()" (fn [t]
+ (t (let [spaces [[1 2 3] [1 10 22]]
+ moves [2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] ]
+ {:given "spaces [[1 2 3] [1 10 22]]"
+ :should "map to moves"
+ :expected [[2 2 2] [2 0 0]]
+ :actual (candidate-moves moves spaces)}))))
+
+ (describe "mill-at?()" (fn [t]
+ (t
+ (let [move 1
+ moves [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] ]
+ {:given "no mills"
+ :should "return false"
+ :expected false
+ :actual (mill-at? mills moves move)}))
+ (t
+ (let [move 4
+ moves [1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
+ with-mills (partial mill-at? mills)
+ with-moves (partial with-mills moves)]
+ {:given "a mill but not at Move"
+ :should "return false"
+ :expected false
+ :actual (with-moves move)}))
+ (t
+ (let [move 1
+ moves [2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
+ with-mills (partial mill-at? mills)
+ with-moves (partial with-mills moves)]
+ {:given "a mill"
+ :should "return true"
+ :expected true
+ :actual (with-moves move) }))
+ (t
+ (let [move 1
+ moves [2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
+ with-mills (partial mill-at? mills)
+ with-moves (partial with-mills moves)]
+ {:given "a mill"
+ :should "return the opposite of false"
+ :expected false
+ :actual (not (with-moves move)) }))))
+
+ (test-end))))