forked from aldewereld/game_of_life
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_world.py
45 lines (40 loc) · 1.19 KB
/
test_world.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
from unittest import TestCase
from World import *
class TestWorld(TestCase):
"""
Test cases for ``World`` data type.
"""
def setUp(self):
"""
Common setup for running tests
"""
self.width, self.height = 10, 12
self.world = World(self.width, self.height)
def test_set(self):
"""
Tests setting value on location (x,y).
"""
x, y = 4, 6
self.world.set(x, y)
self.assertEqual(self.world.world[y][x], 1)
value = 7
self.world.set(x, y, 7)
self.assertEqual(self.world.world[y][x], 7)
def test_get(self):
"""
Tests getting value from location (x, y).
"""
x, y = 3, 5
value = 3
self.world.world[y][x] = 3
self.assertEqual(self.world.get(x, y), value)
def test_get_neighbours(self):
"""
Tests getting neighbours from location.
"""
x, y = 2, 0
value = 4
self.world.set(x, self.height-1, value)
neighbours = self.world.get_neighbours(x, y)
self.assertEqual(8, len(neighbours))
self.assertIn(value, neighbours)