This repository was archived by the owner on Mar 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminesweeper_test.py
More file actions
72 lines (51 loc) · 2.31 KB
/
Copy pathminesweeper_test.py
File metadata and controls
72 lines (51 loc) · 2.31 KB
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
import unittest
from minesweeper import annotate
# Tests adapted from `problem-specifications//canonical-data.json`
class MinesweeperTest(unittest.TestCase):
def test_no_rows(self):
self.assertEqual(annotate([]), [])
def test_no_columns(self):
self.assertEqual(annotate([""]), [""])
def test_no_mines(self):
self.assertEqual(annotate([" ", " ", " "]), [" ", " ", " "])
def test_minefield_with_only_mines(self):
self.assertEqual(annotate(["***", "***", "***"]), ["***", "***", "***"])
def test_mine_surrounded_by_spaces(self):
self.assertEqual(annotate([" ", " * ", " "]), ["111", "1*1", "111"])
def test_space_surrounded_by_mines(self):
self.assertEqual(annotate(["***", "* *", "***"]), ["***", "*8*", "***"])
def test_horizontal_line(self):
self.assertEqual(annotate([" * * "]), ["1*2*1"])
def test_horizontal_line_mines_at_edges(self):
self.assertEqual(annotate(["* *"]), ["*1 1*"])
def test_vertical_line(self):
self.assertEqual(annotate([" ", "*", " ", "*", " "]), ["1", "*", "2", "*", "1"])
def test_vertical_line_mines_at_edges(self):
self.assertEqual(annotate(["*", " ", " ", " ", "*"]), ["*", "1", " ", "1", "*"])
def test_cross(self):
self.assertEqual(
annotate([" * ", " * ", "*****", " * ", " * "]),
[" 2*2 ", "25*52", "*****", "25*52", " 2*2 "],
)
def test_large_minefield(self):
self.assertEqual(
annotate([" * * ", " * ", " * ", " * *", " * * ", " "]),
["1*22*1", "12*322", " 123*2", "112*4*", "1*22*2", "111111"],
)
# Additional tests for this track
def test_annotate_9(self):
self.assertEqual(
annotate([" ", " * ", " ", " ", " * "]),
[" 111", " 1*1", " 111", "111 ", "1*1 "],
)
def test_different_len(self):
with self.assertRaisesWithMessage(ValueError):
annotate([" ", "* ", " "])
def test_invalid_char(self):
with self.assertRaisesWithMessage(ValueError):
annotate(["X * "])
# Utility functions
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
if __name__ == "__main__":
unittest.main()