-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_minesweeper.py
60 lines (52 loc) · 1.66 KB
/
test_minesweeper.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
import unittest
from minesweeper import *
from termcolor import colored
class TestTileMethods(unittest.TestCase):
def test_init(self):
a = Tile(1)
self.assertEqual(a.isBomb, False)
self.assertEqual(a.neighboring, [])
self.assertEqual(a.id, 1)
self.assertEqual(a.mouse, False)
self.assertEqual(a.flagged, False)
self.assertEqual(a.hidden, True)
def test_neighbors(self):
a = Tile(1)
b = Tile(2)
c = Tile(3)
arr = []
for i in range(10):
arr.append(Tile(i + 3))
a.addNeighboring(b)
self.assertEqual(a.getNeighboring(), [b])
a.addNeighboring(arr)
self.assertEqual(a.getNeighboring(), [b] + arr)
a.neighboring = []
self.assertEqual(a.getNeighboring(), [])
def test_tile_to_string(self):
a = Tile(1)
self.assertEqual(str(a), '#')
a.hidden = False
a.numNeighboringBombs = 0
self.assertEqual(str(a), colored(' ', 'cyan'))
a.hidden = True
a.flagged = True
self.assertEqual(str(a), colored('F', 'red'))
a.mouse = True
self.assertEqual(str(a), colored('X', 'yellow'))
a.mouse = False
a.isBomb = True
a.hidden = False
a.flagged = False
self.assertEqual(str(a), colored('B', 'magenta'))
def test_show(self):
a = Tile(1)
b = Tile(2)
self.assertEqual(a.hidden, True)
a.numNeighboringBombs = 1
self.assertEqual(a.show(), 0)
b.numNeighboringBombs = 1
b.isBomb = True
self.assertEqual(b.show(), 1)
if __name__ == '__main__':
unittest.main(verbosity=3)