Skip to content

Commit d5e3cd7

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. Closes #998
1 parent 0c501fa commit d5e3cd7

File tree

1 file changed

+108
-64
lines changed

1 file changed

+108
-64
lines changed

exercises/minesweeper/minesweeper_test.py

Lines changed: 108 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,114 +10,158 @@
1010

1111
from minesweeper import board
1212

13+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
14+
1315

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+
# self.assertEqual(board([]), [])
20+
21+
# def test_no_columns(self):
22+
# self.assertEqual(board([""]), [""])
23+
24+
def test_no_mines(self):
25+
inp = ["+---+",
26+
"| |",
27+
"| |",
28+
"| |",
29+
"+---+"]
30+
out = ["+---+",
31+
"| |",
32+
"| |",
33+
"| |",
34+
"+---+"]
35+
self.assertEqual(board(inp), out)
36+
37+
def test_board_with_only_mines(self):
38+
inp = ["+---+",
39+
"|***|",
40+
"|***|",
41+
"|***|",
42+
"+---+"]
43+
out = ["+---+",
44+
"|***|",
45+
"|***|",
46+
"|***|",
47+
"+---+"]
48+
self.assertEqual(board(inp), out)
49+
50+
def test_mine_surrounded_by_spaces(self):
51+
inp = ["+---+",
52+
"| |",
53+
"| * |",
54+
"| |",
55+
"+---+"]
56+
out = ["+---+",
57+
"|111|",
58+
"|1*1|",
59+
"|111|",
60+
"+---+"]
61+
self.assertEqual(board(inp), out)
62+
63+
def test_space_surrounded_by_mines(self):
64+
inp = ["+---+",
65+
"|***|",
66+
"|* *|",
67+
"|***|",
68+
"+---+"]
69+
out = ["+---+",
70+
"|***|",
71+
"|*8*|",
72+
"|***|",
73+
"+---+"]
3274
self.assertEqual(board(inp), out)
3375

34-
def test_board2(self):
76+
def test_horizontal_line(self):
3577
inp = ["+-----+",
36-
"| * * |",
37-
"| |",
38-
"| * |",
39-
"| * *|",
4078
"| * * |",
4179
"+-----+"]
4280
out = ["+-----+",
4381
"|1*2*1|",
44-
"|11322|",
45-
"| 12*2|",
46-
"|12*4*|",
47-
"|1*3*2|",
4882
"+-----+"]
4983
self.assertEqual(board(inp), out)
5084

51-
def test_board3(self):
85+
def test_horizontal_line_mines_at_edges(self):
5286
inp = ["+-----+",
53-
"| * * |",
87+
"|* *|",
5488
"+-----+"]
5589
out = ["+-----+",
56-
"|1*2*1|",
90+
"|*1 1*|",
5791
"+-----+"]
5892
self.assertEqual(board(inp), out)
5993

60-
def test_board4(self):
94+
def test_vertical_line(self):
6195
inp = ["+-+",
62-
"|*|",
6396
"| |",
6497
"|*|",
6598
"| |",
99+
"|*|",
66100
"| |",
67101
"+-+"]
68102
out = ["+-+",
103+
"|1|",
69104
"|*|",
70105
"|2|",
71106
"|*|",
72107
"|1|",
73-
"| |",
74108
"+-+"]
75109
self.assertEqual(board(inp), out)
76110

77-
def test_board5(self):
111+
def test_vertical_line_mines_at_edges(self):
78112
inp = ["+-+",
113+
"|*|",
114+
"| |",
115+
"| |",
116+
"| |",
79117
"|*|",
80118
"+-+"]
81119
out = ["+-+",
120+
"|*|",
121+
"|1|",
122+
"| |",
123+
"|1|",
82124
"|*|",
83125
"+-+"]
84126
self.assertEqual(board(inp), out)
85127

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-
"+--+"]
128+
def test_cross(self):
129+
inp = ["+-----+",
130+
"| * |",
131+
"| * |",
132+
"|*****|",
133+
"| * |",
134+
"| * |",
135+
"+-----+"]
136+
out = ["+-----+",
137+
"| 2*2 |",
138+
"|25*52|",
139+
"|*****|",
140+
"|25*52|",
141+
"| 2*2 |",
142+
"+-----+"]
106143
self.assertEqual(board(inp), out)
107144

108-
def test_board8(self):
109-
inp = ["+---+",
110-
"|***|",
111-
"|* *|",
112-
"|***|",
113-
"+---+"]
114-
out = ["+---+",
115-
"|***|",
116-
"|*8*|",
117-
"|***|",
118-
"+---+"]
145+
def test_large_board(self):
146+
inp = ["+------+",
147+
"| * * |",
148+
"| * |",
149+
"| * |",
150+
"| * *|",
151+
"| * * |",
152+
"| |",
153+
"+------+"]
154+
out = ["+------+",
155+
"|1*22*1|",
156+
"|12*322|",
157+
"| 123*2|",
158+
"|112*4*|",
159+
"|1*22*2|",
160+
"|111111|",
161+
"+------+"]
119162
self.assertEqual(board(inp), out)
120163

164+
# Additional test for this track
121165
def test_board9(self):
122166
inp = ["+-----+",
123167
"| |",

0 commit comments

Comments
 (0)