2024-05-30 01:26:41 +00:00
|
|
|
(let [{: describe
|
|
|
|
:end test-end} (require :lib.test)
|
2024-06-03 20:41:37 +00:00
|
|
|
{: mill-at?
|
2024-05-30 01:26:41 +00:00
|
|
|
: get-candidates
|
2024-06-03 20:41:37 +00:00
|
|
|
: move-mills
|
|
|
|
: candidate-moves
|
2024-05-30 01:26:41 +00:00
|
|
|
: any
|
|
|
|
} (require :lib.mill)
|
|
|
|
{: mills } (require :lib.constants)
|
2024-06-03 20:41:37 +00:00
|
|
|
with-mills (partial mill-at? mills)]
|
2024-05-30 01:26:41 +00:00
|
|
|
|
|
|
|
(describe "Mill" (fn []
|
|
|
|
(describe "#get-candidates()" (fn [t]
|
|
|
|
(t
|
2024-06-03 20:41:37 +00:00
|
|
|
(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)
|
|
|
|
}))
|
2024-05-30 01:26:41 +00:00
|
|
|
(t
|
2024-06-03 20:41:37 +00:00
|
|
|
(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)
|
|
|
|
}))
|
|
|
|
))
|
|
|
|
|
2024-05-30 01:26:41 +00:00
|
|
|
(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])
|
|
|
|
})))
|
|
|
|
|
2024-06-03 20:41:37 +00:00
|
|
|
(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)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
))
|
2024-05-30 01:26:41 +00:00
|
|
|
|
2024-06-03 20:41:37 +00:00
|
|
|
(describe "#mill-at?()" (fn [t]
|
2024-05-30 01:26:41 +00:00
|
|
|
(t
|
|
|
|
(let [move 1
|
2024-06-03 20:41:37 +00:00
|
|
|
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)
|
2024-05-30 01:26:41 +00:00
|
|
|
with-moves (partial with-mills moves)]
|
2024-06-03 20:41:37 +00:00
|
|
|
{:given "a mill but not at Move"
|
|
|
|
:should "return false"
|
2024-05-30 01:26:41 +00:00
|
|
|
:expected false
|
2024-06-03 20:41:37 +00:00
|
|
|
:actual (with-moves move)
|
2024-05-30 01:26:41 +00:00
|
|
|
}))
|
|
|
|
(t
|
2024-06-03 20:41:37 +00:00
|
|
|
(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)
|
2024-05-30 01:26:41 +00:00
|
|
|
with-moves (partial with-mills moves)]
|
2024-06-03 20:41:37 +00:00
|
|
|
{:given "a mill"
|
|
|
|
:should "return true"
|
2024-05-30 01:26:41 +00:00
|
|
|
:expected true
|
2024-06-03 20:41:37 +00:00
|
|
|
:actual (with-moves move)
|
2024-05-30 01:26:41 +00:00
|
|
|
}))
|
|
|
|
(t
|
2024-06-03 20:41:37 +00:00
|
|
|
(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)
|
2024-05-30 01:26:41 +00:00
|
|
|
with-moves (partial with-mills moves)]
|
2024-06-03 20:41:37 +00:00
|
|
|
{:given "a mill"
|
|
|
|
:should "return the opposite of false"
|
|
|
|
:expected false
|
|
|
|
:actual (not (with-moves move))
|
|
|
|
}))
|
|
|
|
))
|
|
|
|
|
2024-05-30 01:26:41 +00:00
|
|
|
(test-end))))
|