-
Notifications
You must be signed in to change notification settings - Fork 1
/
Board_Test.hs
70 lines (58 loc) · 2.54 KB
/
Board_Test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- Board_Test.hs
-- Tests of Board.hs
import Types
import Board
import Test.HUnit
sampleBoard = ([3, 5, 0, 1, 3], [7, 0, 1, 1, 2])
sampleHoles = [3, 5, 0, 1, 3, 7, 0, 1, 1, 2]
initBoardTest = TestList [
TestCase $ assertEqual "Inits a board with 5 holes (including mancala hole) with 4 seeds"
(initBoard 5 4) ([4, 4, 4, 4, 4, 0], [4, 4, 4, 4, 4, 0])
]
getPlayerHolesTest = TestList [
TestCase $ assertEqual "Returns player A holes"
[3, 5, 0, 1, 3] (getPlayerHoles A sampleBoard),
TestCase $ assertEqual "Returns player B holes"
[7, 0, 1, 1, 2] (getPlayerHoles B sampleBoard)
]
removeMancalaHoleTest = TestList [
TestCase $ assertEqual "Removes mancala hole"
[3, 4, 0, 1] (removeMancalaHole [3, 4, 0, 1, 7])
]
updateHoleTest = TestList [
TestCase $ assertEqual "Updates player A hole 1 to 0"
([3, 0, 0, 1, 3] ++ snd sampleBoard) (updateHole 1 0 (board2holes A sampleBoard)),
TestCase $ assertEqual "Updates player B hole 3 to 0"
([7, 0, 1, 0, 2] ++ fst sampleBoard) (updateHole 3 0 (board2holes B sampleBoard))
]
sowTest = TestList [
TestCase $ assertEqual "Sows holes with 3 seeds initiating by hole 0"
([4, 1, 5, 7, 2, 6]) (sow 3 0 [3, 0, 4, 7, 2, 6]),
TestCase $ assertEqual "Sows holes with 7 seeds initiating by hole 2"
([4, 1, 6, 9, 3, 6]) (sow 7 2 [3, 0, 4, 7, 2, 6]),
TestCase $ assertEqual "Sows holes with 10 seeds initiating by hole 2"
([5, 2, 6, 9, 4, 6]) (sow 10 2 [3, 0, 4, 7, 2, 6])
]
moveTest = TestList [
TestCase $ assertEqual "Player A moves from hole 3"
([3, 5, 0, 0, 4], snd sampleBoard) (move (A, 3) sampleBoard),
TestCase $ assertEqual "Player A moves from hole 1"
([3, 0, 1, 2, 4], [8, 1, 1, 1, 2]) (move (A, 1) sampleBoard),
TestCase $ assertEqual "Player B moves from hole 0"
([4, 6, 1, 1, 3], [0, 1, 2, 2, 3]) (move (B, 0) sampleBoard)
]
captureTest = TestList [
TestCase $ assertEqual "Player A captures from hole 3"
([3, 5, 0, 1, 10], [0, 0, 1, 1, 2]) (capture (A, 3) sampleBoard),
TestCase $ assertEqual "Player B captures from hole 0"
([3, 0, 0, 1, 3], [7, 0, 1, 1, 7]) (capture (B, 2) sampleBoard)
]
getLastHoleTest = TestList [
TestCase $ assertEqual "Return last hole from hole 6"
(A, 6) (getLastHole (A, 4) ([4, 0, 5, 5, 15, 5, 1], [4, 4, 4, 4, 4, 4, 0])),
TestCase $ assertEqual "Return last hole from hoke 4"
(B, 0) (getLastHole (A, 2) ([4, 0, 5, 5, 15, 5, 1], [4, 4, 4, 4, 4, 4, 0]))
]
main = runTestTT $ TestList [initBoardTest, removeMancalaHoleTest,
getPlayerHolesTest, updateHoleTest, sowTest, captureTest,
getLastHoleTest]