summaryrefslogtreecommitdiff
path: root/lib/mill.test.fnl
diff options
context:
space:
mode:
authordozens2024-05-29 19:26:41 -0600
committerdozens2024-06-02 21:44:17 -0600
commit7c07d6e6ececbf73e18a639e00b3690d4827e12a (patch)
tree7d948da1b634d100feb32215dd5d263c5b01ab8b /lib/mill.test.fnl
parentf265d24c0cacb92c7f7db19f364a155d87938184 (diff)
tests
Diffstat (limited to 'lib/mill.test.fnl')
-rw-r--r--lib/mill.test.fnl142
1 files changed, 141 insertions, 1 deletions
diff --git a/lib/mill.test.fnl b/lib/mill.test.fnl
index 358b218..8bd3522 100644
--- a/lib/mill.test.fnl
+++ b/lib/mill.test.fnl
@@ -1 +1,141 @@
-;; TODO: test me
+(let [{: describe
+ :end test-end} (require :lib.test)
+ {: mill?
+ : get-candidates
+ : candidates->moves
+ : moves->mills
+ : any
+ } (require :lib.mill)
+ {: mills } (require :lib.constants)
+ with-mills (partial mill? 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)
+ }))))
+
+
+ (describe "#candidates->moves()" (fn [t]
+ (t
+ (let [candidates [[1 2 3] [1 10 22]]
+ moves [0 1 1 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 2]
+ expected [[:x 1 1] [:x 2 2]]
+ move 1
+ player 2
+ ]
+ {:given "a list of spaces and of current moves"
+ :should "return a map of spaces to moves"
+ : expected
+ :actual (candidates->moves candidates moves move player)
+ }))
+ (t
+ (let [candidates [[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 ]
+ expected [[1 1 :x] [:x 0 0]]
+ move 3
+ player 1
+ ]
+ {:given "a list of candidates and of current moves"
+ :should "return an x-map of spaces to moves"
+ : expected
+ :actual (candidates->moves candidates moves move player)
+ }))))
+
+
+ (describe "#moves->mills()" (fn [t]
+ (t
+ (let [spaces [[:x 1 1] [:x 2 2]]
+ moves [0 1 1 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 2]
+ player 2
+ ]
+ {:given "a list of spaces and of current moves"
+ :should "return a map of spaces to moves"
+ :expected [false true]
+ :actual (moves->mills spaces player)
+ }))
+ (t
+ (let [spaces [[1 1 :x] [:x 0 0]]
+ 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 ]
+ player 1
+ ]
+ {:given "a list of canditate-moves and of current moves"
+ :should "return a map of spaces to moves"
+ :expected [true false]
+ :actual (moves->mills spaces player)
+ }))))
+
+
+ (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 "#mill?()" (fn [t]
+ (t
+ (let [move 1
+ player 1
+ moves [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
+ with-moves (partial with-mills moves)]
+ {:given (string.format "a move of P%d:%d with moves %s" player move (table.concat moves ","))
+ :should "not be a mill"
+ :expected false
+ :actual (with-moves move player)
+ }))
+ (t
+ (let [move 3
+ player 1
+ moves [1 1 0]
+ with-moves (partial with-mills moves)]
+ {:given (string.format "a move of P%d:%d with moves %s" player move (table.concat moves ","))
+ :should "be a mill"
+ :expected true
+ :actual (with-moves move player)
+ }))
+ (t
+ (let [move 3
+ player 1
+ 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 ]
+ with-moves (partial with-mills moves)]
+ {:given (string.format "a move of P%d:%d with moves %s" player move (table.concat moves ","))
+ :should "be a mill"
+ :expected true
+ :actual (with-moves move player)
+ }))))
+ (test-end))))