Skip to content

Commit 71ac523

Browse files
committed
minesweeper: update tests to version 1.1.0
Add missing test version comment. Add ordered tests with names matching canonical data descriptions. Disable empty board tests which are incompatible with board class. Move selected old tests to additional tests section. Convert no row/column tests to expect validation to raise ValueError. Closes #998
1 parent 9f25653 commit 71ac523

File tree

1 file changed

+110
-64
lines changed

1 file changed

+110
-64
lines changed

exercises/minesweeper/minesweeper_test.py

Lines changed: 110 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,113 +11,159 @@
1111
from minesweeper import board
1212

1313

14+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
15+
1416
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+
"+---+"]
3276
self.assertEqual(board(inp), out)
3377

34-
def test_board2(self):
78+
def test_horizontal_line(self):
3579
inp = ["+-----+",
36-
"| * * |",
37-
"| |",
38-
"| * |",
39-
"| * *|",
4080
"| * * |",
4181
"+-----+"]
4282
out = ["+-----+",
4383
"|1*2*1|",
44-
"|11322|",
45-
"| 12*2|",
46-
"|12*4*|",
47-
"|1*3*2|",
4884
"+-----+"]
4985
self.assertEqual(board(inp), out)
5086

51-
def test_board3(self):
87+
def test_horizontal_line_mines_at_edges(self):
5288
inp = ["+-----+",
53-
"| * * |",
89+
"|* *|",
5490
"+-----+"]
5591
out = ["+-----+",
56-
"|1*2*1|",
92+
"|*1 1*|",
5793
"+-----+"]
5894
self.assertEqual(board(inp), out)
5995

60-
def test_board4(self):
96+
def test_vertical_line(self):
6197
inp = ["+-+",
62-
"|*|",
6398
"| |",
6499
"|*|",
65100
"| |",
101+
"|*|",
66102
"| |",
67103
"+-+"]
68104
out = ["+-+",
105+
"|1|",
69106
"|*|",
70107
"|2|",
71108
"|*|",
72109
"|1|",
73-
"| |",
74110
"+-+"]
75111
self.assertEqual(board(inp), out)
76112

77-
def test_board5(self):
113+
def test_vertical_line_mines_at_edges(self):
78114
inp = ["+-+",
115+
"|*|",
116+
"| |",
117+
"| |",
118+
"| |",
79119
"|*|",
80120
"+-+"]
81121
out = ["+-+",
122+
"|*|",
123+
"|1|",
124+
"| |",
125+
"|1|",
82126
"|*|",
83127
"+-+"]
84128
self.assertEqual(board(inp), out)
85129

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+
"+-----+"]
106145
self.assertEqual(board(inp), out)
107146

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+
"+------+"]
119164
self.assertEqual(board(inp), out)
120165

166+
# Additional test for this track
121167
def test_board9(self):
122168
inp = ["+-----+",
123169
"| |",

0 commit comments

Comments
 (0)