9mm/lib/mill.test.fnl

142 lines
4.4 KiB
Plaintext
Raw Normal View History

2024-05-30 01:26:41 +00:00
(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))))