-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
100 lines (87 loc) · 2.32 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
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
from main import next_board_state
# TODO: there's a lot of repeated code here. Can
# you move some of into reusable functions to
# make it shorter and neater?
if __name__ == "__main__":
# TEST 1: dead cells with no live neighbors
# should stay dead.
init_state1 = [
[0,0,0],
[0,0,0],
[0,0,0]
]
expected_next_state1 = [
[0,0,0],
[0,0,0],
[0,0,0]
]
actual_next_state1 = next_board_state(init_state1)
if expected_next_state1 == actual_next_state1:
print("PASSED 1")
else:
print("FAILED 1!")
print("Expected:")
print (expected_next_state1)
print ("Actual:")
print (actual_next_state1)
# TEST 2: dead cells with exactly 3 neighbors
# should come alive.
init_state2 = [
[0,0,1],
[0,1,1],
[0,0,0]
]
expected_next_state2 = [
[0,1,1],
[0,1,1],
[0,0,0]
]
actual_next_state2 = next_board_state(init_state2)
if expected_next_state2 == actual_next_state2:
print ("PASSED 2")
else:
print ("FAILED 2!")
print ("Expected:")
print (expected_next_state2)
print ("Actual:")
print (actual_next_state2)
#TEST 3: live cells with more than 3 neighbors, dead because of overpopulation
init_state3 = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
]
expected_next_state3 = [
[1, 0, 1],
[0, 0, 0],
[1, 0, 1]
]
actual_next_state3 = next_board_state(init_state3)
if expected_next_state3 == actual_next_state3:
print ("PASSED 3")
else:
print ("FAILED 3!")
print ("Expected:")
print (expected_next_state3)
print ("Actual:")
print (actual_next_state3)
#TEST 4: dead cells with exactly 3 neighbors become alive, because of reproduction
init_state4 = [
[0, 1, 1],
[1, 1, 0],
[0, 1, 1]
]
expected_next_state4 = [
[1, 1, 1],
[1, 0, 0],
[1, 1, 1]
]
actual_next_state4 = next_board_state(init_state4)
if expected_next_state4 == actual_next_state4:
print ("PASSED 4")
else:
print ("FAILED 4!")
print ("Expected:")
print (expected_next_state4)
print ("Actual:")
print (actual_next_state4)