This repository has been archived by the owner on Jan 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoardTest.hs
131 lines (119 loc) · 5.98 KB
/
BoardTest.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
module BoardTest where
import Board
import Test.HUnit
empty_grid_0_0 = []
empty_grid_1_1 = [[0]]
empty_grid_1_2 = [[0,0]]
empty_grid_2_2 = [[0,0],
[0,0]]
empty_grid_3_3 = [[0,0,0],
[0,0,0],
[0,0,0]]
empty_grid_6_7 = [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0]]
test_new_grid_00 = TestCase (assertEqual "new_grid" (new_grid 0 0) empty_grid_0_0)
test_new_grid_11 = TestCase (assertEqual "new_grid" (new_grid 1 1) empty_grid_1_1)
test_new_grid_12 = TestCase (assertEqual "new_grid" (new_grid 1 2) empty_grid_1_2)
test_new_grid_22 = TestCase (assertEqual "new_grid" (new_grid 2 2) empty_grid_2_2)
test_new_grid_33 = TestCase (assertEqual "new_grid" (new_grid 3 3) empty_grid_3_3)
test_new_grid_67 = TestCase (assertEqual "new_grid" (new_grid 6 7) empty_grid_6_7)
mostly_full_grid = [[2,0,0,1,0,2,0],
[2,1,2,1,2,1,2],
[1,2,2,1,1,2,1],
[2,1,1,2,2,1,2],
[2,2,1,1,1,2,2],
[1,2,1,1,2,1,1]]
test_is_valid_move_col_1 = TestCase (assertBool "valid_move" (is_valid_move mostly_full_grid 1))
test_is_valid_move_col_2 = TestCase (assertBool "valid_move" (is_valid_move mostly_full_grid 2))
test_is_valid_move_col_4 = TestCase (assertBool "valid_move" (is_valid_move mostly_full_grid 4))
test_is_valid_move_col_6 = TestCase (assertBool "valid_move" (is_valid_move mostly_full_grid 6))
test_is_not_valid_move_col_0 = TestCase (assertEqual "valid_move" (is_valid_move mostly_full_grid 0) False)
test_is_not_valid_move_col_3 = TestCase (assertEqual "valid_move" (is_valid_move mostly_full_grid 3) False)
test_is_not_valid_move_col_5 = TestCase (assertEqual "valid_move" (is_valid_move mostly_full_grid 5) False)
grid_move_0_1 = [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[1,0,0,0,0,0,0]]
grid_move_0_2 = [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[2,0,0,0,0,0,0],
[1,0,0,0,0,0,0]]
grid_move_1_1 = [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[2,0,0,0,0,0,0],
[1,1,0,0,0,0,0]]
grid_move_2_2 = [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[2,0,0,0,0,0,0],
[1,1,2,0,0,0,0]]
grid_move_6_1 = [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[2,0,0,0,0,0,0],
[1,1,2,0,0,0,1]]
grid_move_4_2 = [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[2,0,0,0,0,0,0],
[1,1,2,0,2,0,1]]
test_apply_move_0_1 = TestCase (assertEqual "apply_move" (apply_move empty_grid_6_7 0 1) grid_move_0_1)
test_apply_move_0_2 = TestCase (assertEqual "apply_move" (apply_move grid_move_0_1 0 2) grid_move_0_2)
test_apply_move_1_1 = TestCase (assertEqual "apply_move" (apply_move grid_move_0_2 1 1) grid_move_1_1)
test_apply_move_2_2 = TestCase (assertEqual "apply_move" (apply_move grid_move_1_1 2 2) grid_move_2_2)
test_apply_move_6_1 = TestCase (assertEqual "apply_move" (apply_move grid_move_2_2 6 1) grid_move_6_1)
test_apply_move_4_2 = TestCase (assertEqual "apply_move" (apply_move grid_move_6_1 4 2) grid_move_4_2)
win_grid = [[0,2,0,0,0,0,0],
[0,2,0,0,0,0,0],
[0,2,0,2,0,0,0],
[0,2,1,1,2,0,0],
[0,1,2,2,1,2,0],
[1,2,1,1,1,1,2]]
test_win_col0_p1 = TestCase (assertBool "is_win" (is_win win_grid 0 1))
test_win_col1_p2 = TestCase (assertBool "is_win" (is_win win_grid 1 2))
test_win_col3_p2 = TestCase (assertBool "is_win" (is_win win_grid 3 2))
test_no_win_col1_p1 = TestCase (assertEqual "is_win" (is_win win_grid 1 1) False)
test_no_win_col2_p2 = TestCase (assertEqual "is_win" (is_win win_grid 2 2) False)
test_no_win_col3_p1 = TestCase (assertEqual "is_win" (is_win win_grid 3 1) False)
tests = TestList [TestLabel "testGrid00" test_new_grid_00,
TestLabel "testGrid11" test_new_grid_11,
TestLabel "testGrid12" test_new_grid_12,
TestLabel "testGrid22" test_new_grid_22,
TestLabel "testGrid22" test_new_grid_33,
TestLabel "testGrid67" test_new_grid_67,
TestLabel "testValidMoveCol1" test_is_valid_move_col_1,
TestLabel "testValidMoveCol2" test_is_valid_move_col_2,
TestLabel "testValidMoveCol4" test_is_valid_move_col_4,
TestLabel "testValidMoveCol6" test_is_valid_move_col_6,
TestLabel "testInvalidMoveCol0" test_is_not_valid_move_col_0,
TestLabel "testInvalidMoveCol3" test_is_not_valid_move_col_3,
TestLabel "testInvalidMoveCol5" test_is_not_valid_move_col_5,
TestLabel "testApplyMove01" test_apply_move_0_1,
TestLabel "testApplyMove02" test_apply_move_0_2,
TestLabel "testApplyMove11" test_apply_move_1_1,
TestLabel "testApplyMove22" test_apply_move_2_2,
TestLabel "testApplyMove61" test_apply_move_6_1,
TestLabel "testApplyMove42" test_apply_move_4_2,
TestLabel "testWinCol0P1" test_win_col0_p1,
TestLabel "testWinCol1P2" test_win_col1_p2,
TestLabel "testWinCol3P2" test_win_col3_p2,
TestLabel "testNoWinCol1P1" test_no_win_col1_p1,
TestLabel "testNoWinCol2P2" test_no_win_col2_p2,
TestLabel "testNoWinCol3P1" test_no_win_col3_p1]
main :: IO ()
main = do
runTestTT tests
return ()