-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gol.py
67 lines (60 loc) · 1.51 KB
/
test_gol.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
# -*- coding: utf-8 -*-
import unittest
from gol import parse_world, print_world, alive_neighbor_count, Coords
class GameOfLifeTests(unittest.TestCase):
def assert_neighbors(self, str, p, expected):
rows = [s.strip() for s in str.split('\n')]
world = parse_world(rows)
#print_world(world)
count = alive_neighbor_count(Coords(p[0],p[1]), world)
self.assertEqual(expected, count)
def test_alive_neighbor_case_top_left(self):
self.assert_neighbors(
"""##~
##~
~~~""", (0,0), 3)
def test_alive_neighbor_case_top_middle(self):
self.assert_neighbors(
"""###
###
~~~""", (0,1), 5)
def test_alive_neighbor_case_top_right(self):
self.assert_neighbors(
"""###
###
~~~""", (0,2), 3)
def test_alive_neighbor_case_middle_left(self):
self.assert_neighbors(
"""##~
##~
##~""", (1,0), 5)
def test_alive_neighbor_case_middle_empty(self):
self.assert_neighbors(
"""~~~
~#~
~~~""", (1,1), 0)
def test_alive_neighbor_case_middle_full(self):
self.assert_neighbors(
"""###
###
###""", (1,1), 8)
def test_alive_neighbor_case_middle_right(self):
self.assert_neighbors(
"""~##
~##
~##""", (1,2), 5)
def test_alive_neighbor_case_bottom_left(self):
self.assert_neighbors(
"""##~
##~
##~""", (2,0), 3)
def test_alive_neighbor_case_bottom_middle(self):
self.assert_neighbors(
"""~~~
###
###""", (2,1), 5)
def test_alive_neighbor_case_bottom_right(self):
self.assert_neighbors(
"""~~~
###
###""", (2,2), 3)