From 7776b2011a2585723078b275c838fd7332488d76 Mon Sep 17 00:00:00 2001 From: dozens Date: Mon, 3 Jun 2024 14:41:37 -0600 Subject: feat: capturing cannot break a mill refactors the way mill? is written to make it a little more versatile --- lib/mill.test.fnl | 199 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 104 insertions(+), 95 deletions(-) (limited to 'lib/mill.test.fnl') diff --git a/lib/mill.test.fnl b/lib/mill.test.fnl index 8bd3522..04f7e97 100644 --- a/lib/mill.test.fnl +++ b/lib/mill.test.fnl @@ -1,89 +1,48 @@ (let [{: describe :end test-end} (require :lib.test) - {: mill? + {: mill-at? : get-candidates - : candidates->moves - : moves->mills + : move-mills + : candidate-moves : any } (require :lib.mill) {: mills } (require :lib.constants) - with-mills (partial mill? mills)] - + 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) - })) + (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) - })))) - - + (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" @@ -106,36 +65,86 @@ :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 spaces moves) + } + ) + ) + )) - (describe "#mill?()" (fn [t] + (describe "#mill-at?()" (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] + 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 (string.format "a move of P%d:%d with moves %s" player move (table.concat moves ",")) - :should "not be a mill" + {:given "a mill but not at Move" + :should "return false" :expected false - :actual (with-moves move player) + :actual (with-moves move) })) (t - (let [move 3 - player 1 - moves [1 1 0] + (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 (string.format "a move of P%d:%d with moves %s" player move (table.concat moves ",")) - :should "be a mill" + {:given "a mill" + :should "return true" :expected true - :actual (with-moves move player) + :actual (with-moves move) })) (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 ] + (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 (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) - })))) + {:given "a mill" + :should "return the opposite of false" + :expected false + :actual (not (with-moves move)) + })) + )) + (test-end)))) -- cgit 1.4.1-2-gfad0