9mm/lib/mill.test.fnl

151 lines
4.5 KiB
Fennel

(let [{: describe
:end test-end} (require :lib.test)
{: mill-at?
: get-candidates
: move-mills
: candidate-moves
: any
} (require :lib.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 spaces moves)
}
)
)
))
(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))))