-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.py
58 lines (48 loc) · 2.08 KB
/
Test.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
import random
import unittest
from unittest.mock import patch, Mock
from Map import Map
class TestClass(unittest.TestCase):
def setUp(self):
self.game_map = Map([[1, 0, 1], [0, 1, 0], [0, 0, 0], [1, 1, 0]])
def test_height(self):
self.assertEqual(4, self.game_map.height, "Should get correct rows")
def test_width(self):
self.assertEqual(3, self.game_map.width, "Should get correct cols")
def test_get_set(self):
self.assertEqual(1, self.game_map.get_cell(1, 1))
self.game_map.set_cell(1, 1, 0)
self.assertEqual(0, self.game_map.get_cell(1, 1))
def test_flip(self):
self.assertEqual(0, self.game_map.get_cell(0, 1))
self.game_map.flip_cell(0, 1)
self.assertEqual(1, self.game_map.get_cell(0, 1))
@patch('Map.Map.get_neighbor_count_map')
def test_update(self, mock_function):
expected_value = [[0, 1, 0],
[0, 1, 0],
[1, 1, 0],
[0, 0, 0]]
mock_function.return_value = [[1, 3, 1],
[2, 2, 2],
[3, 3, 2],
[1, 1, 1]]
self.game_map.Update()
for i in range(4):
for j in range(3):
self.assertEqual(expected_value[i][j], self.game_map.get_cell(i, j))
def test_get_neighbor_map(self):
expected_value = [[1, 3, 1],
[2, 2, 2],
[3, 3, 2],
[1, 1, 1]]
neighbor_count_map = self.game_map.get_neighbor_count_map()
for i in range(4):
for j in range(3):
self.assertEqual(expected_value[i][j], neighbor_count_map[i][j], '(%d, %d)' % (i, j))
@patch('random.random',new=Mock(side_effect=[1,1,1,1,1,1,1,1,1,1,1,1]))
def test_reset(self):
self.game_map.reset(0.5)
for i in range(4):
for j in range(3):
self.assertEqual(self.game_map.get_cell(i,j),0)