|
11 | 11 | from minesweeper import board
|
12 | 12 |
|
13 | 13 |
|
| 14 | +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 |
| 15 | + |
14 | 16 | class MinesweeperTest(unittest.TestCase):
|
15 |
| - def test_board1(self): |
16 |
| - inp = ["+------+", |
17 |
| - "| * * |", |
18 |
| - "| * |", |
19 |
| - "| * |", |
20 |
| - "| * *|", |
21 |
| - "| * * |", |
22 |
| - "| |", |
23 |
| - "+------+"] |
24 |
| - out = ["+------+", |
25 |
| - "|1*22*1|", |
26 |
| - "|12*322|", |
27 |
| - "| 123*2|", |
28 |
| - "|112*4*|", |
29 |
| - "|1*22*2|", |
30 |
| - "|111111|", |
31 |
| - "+------+"] |
| 17 | + # Tests in canonical data incompatible with board class |
| 18 | + def test_no_rows(self): |
| 19 | + with self.assertRaises(ValueError): |
| 20 | + board([]) |
| 21 | + |
| 22 | + def test_no_columns(self): |
| 23 | + with self.assertRaises(ValueError): |
| 24 | + board([""]) |
| 25 | + |
| 26 | + def test_no_mines(self): |
| 27 | + inp = ["+---+", |
| 28 | + "| |", |
| 29 | + "| |", |
| 30 | + "| |", |
| 31 | + "+---+"] |
| 32 | + out = ["+---+", |
| 33 | + "| |", |
| 34 | + "| |", |
| 35 | + "| |", |
| 36 | + "+---+"] |
| 37 | + self.assertEqual(board(inp), out) |
| 38 | + |
| 39 | + def test_board_with_only_mines(self): |
| 40 | + inp = ["+---+", |
| 41 | + "|***|", |
| 42 | + "|***|", |
| 43 | + "|***|", |
| 44 | + "+---+"] |
| 45 | + out = ["+---+", |
| 46 | + "|***|", |
| 47 | + "|***|", |
| 48 | + "|***|", |
| 49 | + "+---+"] |
| 50 | + self.assertEqual(board(inp), out) |
| 51 | + |
| 52 | + def test_mine_surrounded_by_spaces(self): |
| 53 | + inp = ["+---+", |
| 54 | + "| |", |
| 55 | + "| * |", |
| 56 | + "| |", |
| 57 | + "+---+"] |
| 58 | + out = ["+---+", |
| 59 | + "|111|", |
| 60 | + "|1*1|", |
| 61 | + "|111|", |
| 62 | + "+---+"] |
| 63 | + self.assertEqual(board(inp), out) |
| 64 | + |
| 65 | + def test_space_surrounded_by_mines(self): |
| 66 | + inp = ["+---+", |
| 67 | + "|***|", |
| 68 | + "|* *|", |
| 69 | + "|***|", |
| 70 | + "+---+"] |
| 71 | + out = ["+---+", |
| 72 | + "|***|", |
| 73 | + "|*8*|", |
| 74 | + "|***|", |
| 75 | + "+---+"] |
32 | 76 | self.assertEqual(board(inp), out)
|
33 | 77 |
|
34 |
| - def test_board2(self): |
| 78 | + def test_horizontal_line(self): |
35 | 79 | inp = ["+-----+",
|
36 |
| - "| * * |", |
37 |
| - "| |", |
38 |
| - "| * |", |
39 |
| - "| * *|", |
40 | 80 | "| * * |",
|
41 | 81 | "+-----+"]
|
42 | 82 | out = ["+-----+",
|
43 | 83 | "|1*2*1|",
|
44 |
| - "|11322|", |
45 |
| - "| 12*2|", |
46 |
| - "|12*4*|", |
47 |
| - "|1*3*2|", |
48 | 84 | "+-----+"]
|
49 | 85 | self.assertEqual(board(inp), out)
|
50 | 86 |
|
51 |
| - def test_board3(self): |
| 87 | + def test_horizontal_line_mines_at_edges(self): |
52 | 88 | inp = ["+-----+",
|
53 |
| - "| * * |", |
| 89 | + "|* *|", |
54 | 90 | "+-----+"]
|
55 | 91 | out = ["+-----+",
|
56 |
| - "|1*2*1|", |
| 92 | + "|*1 1*|", |
57 | 93 | "+-----+"]
|
58 | 94 | self.assertEqual(board(inp), out)
|
59 | 95 |
|
60 |
| - def test_board4(self): |
| 96 | + def test_vertical_line(self): |
61 | 97 | inp = ["+-+",
|
62 |
| - "|*|", |
63 | 98 | "| |",
|
64 | 99 | "|*|",
|
65 | 100 | "| |",
|
| 101 | + "|*|", |
66 | 102 | "| |",
|
67 | 103 | "+-+"]
|
68 | 104 | out = ["+-+",
|
| 105 | + "|1|", |
69 | 106 | "|*|",
|
70 | 107 | "|2|",
|
71 | 108 | "|*|",
|
72 | 109 | "|1|",
|
73 |
| - "| |", |
74 | 110 | "+-+"]
|
75 | 111 | self.assertEqual(board(inp), out)
|
76 | 112 |
|
77 |
| - def test_board5(self): |
| 113 | + def test_vertical_line_mines_at_edges(self): |
78 | 114 | inp = ["+-+",
|
| 115 | + "|*|", |
| 116 | + "| |", |
| 117 | + "| |", |
| 118 | + "| |", |
79 | 119 | "|*|",
|
80 | 120 | "+-+"]
|
81 | 121 | out = ["+-+",
|
| 122 | + "|*|", |
| 123 | + "|1|", |
| 124 | + "| |", |
| 125 | + "|1|", |
82 | 126 | "|*|",
|
83 | 127 | "+-+"]
|
84 | 128 | self.assertEqual(board(inp), out)
|
85 | 129 |
|
86 |
| - def test_board6(self): |
87 |
| - inp = ["+--+", |
88 |
| - "|**|", |
89 |
| - "|**|", |
90 |
| - "+--+"] |
91 |
| - out = ["+--+", |
92 |
| - "|**|", |
93 |
| - "|**|", |
94 |
| - "+--+"] |
95 |
| - self.assertEqual(board(inp), out) |
96 |
| - |
97 |
| - def test_board7(self): |
98 |
| - inp = ["+--+", |
99 |
| - "|**|", |
100 |
| - "|**|", |
101 |
| - "+--+"] |
102 |
| - out = ["+--+", |
103 |
| - "|**|", |
104 |
| - "|**|", |
105 |
| - "+--+"] |
| 130 | + def test_cross(self): |
| 131 | + inp = ["+-----+", |
| 132 | + "| * |", |
| 133 | + "| * |", |
| 134 | + "|*****|", |
| 135 | + "| * |", |
| 136 | + "| * |", |
| 137 | + "+-----+"] |
| 138 | + out = ["+-----+", |
| 139 | + "| 2*2 |", |
| 140 | + "|25*52|", |
| 141 | + "|*****|", |
| 142 | + "|25*52|", |
| 143 | + "| 2*2 |", |
| 144 | + "+-----+"] |
106 | 145 | self.assertEqual(board(inp), out)
|
107 | 146 |
|
108 |
| - def test_board8(self): |
109 |
| - inp = ["+---+", |
110 |
| - "|***|", |
111 |
| - "|* *|", |
112 |
| - "|***|", |
113 |
| - "+---+"] |
114 |
| - out = ["+---+", |
115 |
| - "|***|", |
116 |
| - "|*8*|", |
117 |
| - "|***|", |
118 |
| - "+---+"] |
| 147 | + def test_large_board(self): |
| 148 | + inp = ["+------+", |
| 149 | + "| * * |", |
| 150 | + "| * |", |
| 151 | + "| * |", |
| 152 | + "| * *|", |
| 153 | + "| * * |", |
| 154 | + "| |", |
| 155 | + "+------+"] |
| 156 | + out = ["+------+", |
| 157 | + "|1*22*1|", |
| 158 | + "|12*322|", |
| 159 | + "| 123*2|", |
| 160 | + "|112*4*|", |
| 161 | + "|1*22*2|", |
| 162 | + "|111111|", |
| 163 | + "+------+"] |
119 | 164 | self.assertEqual(board(inp), out)
|
120 | 165 |
|
| 166 | + # Additional test for this track |
121 | 167 | def test_board9(self):
|
122 | 168 | inp = ["+-----+",
|
123 | 169 | "| |",
|
|
0 commit comments