-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
111 lines (94 loc) · 2.57 KB
/
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
100
101
102
103
104
105
106
107
108
109
110
import unittest
from game import World, Cell
class WorldTest(unittest.TestCase):
def test_counting_0_corner_cell_neighbours(self):
world = World(2, 2)
world.set([
[Cell(0), Cell(0)],
[Cell(0), Cell(0)]
])
self.assertEqual(0, world.get_neighbourhoods()[0][0])
def test_counting_3_corner_cell_neighbours(self):
world = World(2, 2)
world.set([
[Cell(0), Cell(1)],
[Cell(1), Cell(1)]
])
self.assertEqual(3, world.get_neighbourhoods()[0][0])
def test_counting_4_center_cell_4_neighbours(self):
world = World(3, 2)
world.set([
[Cell(1), Cell(1), Cell(1)],
[Cell(1), Cell(1), Cell(0)]
])
self.assertEqual(4, world.get_neighbourhoods()[0][1])
def test_that_cell_dies_with_0_alive_neighbours(self):
world = World(2, 2)
world.set([
[Cell(1), Cell(0)],
[Cell(0), Cell(0)]
])
world.evolve()
self.assertEqual(0, world.world[0][0].status)
def test_that_cell_dies_with_1_alive_neighbours(self):
world = World(2, 2)
world.set([
[Cell(1), Cell(1)],
[Cell(0), Cell(0)]
])
world.evolve()
self.assertEqual(0, world.world[0][0].status)
def test_that_cell_lives_with_2_alive_neighbours(self):
world = World(2, 2)
world.set([
[Cell(1), Cell(1)],
[Cell(1), Cell(0)]
])
world.evolve()
self.assertEqual(1, world.world[0][0].status)
def test_that_cell_keeps_death_with_2_alive_neighbours(self):
world = World(2, 2)
world.set([
[Cell(0), Cell(1)],
[Cell(1), Cell(0)]
])
world.evolve()
self.assertEqual(0, world.world[0][0].status)
def test_that_cell_lives_with_3_alive_neighbours(self):
world = World(2, 2)
world.set([
[Cell(1), Cell(1)],
[Cell(1), Cell(1)]
])
world.evolve()
self.assertEqual(1, world.world[0][0].status)
def test_that_death_cell_lives_with_3_alive_neighbours(self):
world = World(2, 2)
world.set([
[Cell(0), Cell(1)],
[Cell(1), Cell(1)]
])
world.evolve()
self.assertEqual(1, world.world[0][0].status)
def test_that_cell_dies_with_4_alive_neighbours(self):
world = World(3, 2)
world.set([
[Cell(1), Cell(1), Cell(1)],
[Cell(1), Cell(1), Cell(0)]
])
world.evolve()
self.assertEqual(0, world.world[0][1].status)
def test_that_cell_keeps_death_4_alive_neighbours(self):
world = World(3, 2)
world.set([
[Cell(1), Cell(0), Cell(1)],
[Cell(1), Cell(1), Cell(0)]
])
world.evolve()
self.assertEqual(0, world.world[0][1].status)
class WorldMakeTest(unittest.TestCase):
def test_that_worlds_get_created_with_expected_size(self):
world = World(10, 10)
world.generate()
self.assertEqual(10, len(world.world))
self.assertEqual(10, len(world.world[0]))