-
Notifications
You must be signed in to change notification settings - Fork 0
/
minesweeper_tests.py
99 lines (91 loc) · 4.73 KB
/
minesweeper_tests.py
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
import unittest
from table import Table
from minesweeper import Game, Flags
class MinesweeperTest(unittest.TestCase):
def setUp(self):
self.mines = Table.from_nested_list([
[False, False, False, False],
[False, True, False, False],
[False, False, False, False],
[False, False, False, False],
])
self.flags = Table.from_nested_list([
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
])
def test_reveal_hint(self):
game = Game(self.mines, self.flags)
self.assertEqual(True, game.reveal(0, 0))
self.assertEqual(self.flags, Table.from_nested_list([
[Flags.Revealed, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
]))
def test_reveal_mine(self):
game = Game(self.mines, self.flags)
self.assertEqual(False, game.reveal(1, 1))
self.assertEqual(self.flags, Table.from_nested_list([
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Revealed, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
]))
def test_reveal_empty(self):
game = Game(self.mines, self.flags)
self.assertEqual(True, game.reveal(3, 3))
self.assertEqual(self.flags, Table.from_nested_list([
[Flags.Unknown, Flags.Unknown, Flags.Revealed, Flags.Revealed],
[Flags.Unknown, Flags.Unknown, Flags.Revealed, Flags.Revealed],
[Flags.Revealed, Flags.Revealed, Flags.Revealed, Flags.Revealed],
[Flags.Revealed, Flags.Revealed, Flags.Revealed, Flags.Revealed],
]))
def test_reveal_revealed(self):
self.flags = Table.from_nested_list([
[Flags.Revealed, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
])
game = Game(self.mines, self.flags)
self.assertEqual(True, game.reveal(0, 0))
self.assertEqual(self.flags, Table.from_nested_list([
[Flags.Revealed, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
]))
def test_reveal_marked(self):
self.flags = Table.from_nested_list([
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Marked, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
])
game = Game(self.mines, self.flags)
self.assertEqual(True, game.reveal(1, 1))
self.assertEqual(self.flags, Table.from_nested_list([
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
]))
def test_reveal_revealed_hint(self):
self.flags = Table.from_nested_list([
[Flags.Revealed, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Marked, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
])
game = Game(self.mines, self.flags)
self.assertEqual(True, game.reveal(0, 0))
self.assertEqual(self.flags, Table.from_nested_list([
[Flags.Revealed, Flags.Revealed, Flags.Unknown, Flags.Unknown],
[Flags.Revealed, Flags.Marked, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
[Flags.Unknown, Flags.Unknown, Flags.Unknown, Flags.Unknown],
]))
if __name__ == '__main__':
unittest.main()