-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_life_game.py
96 lines (76 loc) · 2.42 KB
/
test_life_game.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
import numpy as np
from life_game import *
def test_check_neighbours():
#zero is zero
a = np.array([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
assert check_neighbours(1, 1, a) == 0
# skip center
a = np.array([[0, 0, 0],
[0, 1, 0],
[0, 0, 0]])
assert check_neighbours(1, 1, a) == 0
# count top
a = np.array([[1, 1, 1],
[0, 0, 0],
[0, 0, 0]])
assert check_neighbours(1, 1, a) == 3
# count bottom
a = np.array([[0, 0, 0],
[0, 0, 0],
[1, 1, 1]])
assert check_neighbours(1, 1, a) == 3
# count left
a = np.array([[1, 0, 0],
[1, 0, 0],
[1, 0, 0]])
assert check_neighbours(1, 1, a) == 3
# count specific
a = np.array([[1, 0, 0],
[0, 0, 1],
[1, 0, 0]])
assert check_neighbours(1, 1, a) == 3
# count all around
a = np.array([[1, 1, 1],
[1, 0, 1],
[1, 1, 1]])
assert check_neighbours(1, 1, a) == 8
# all alive
a = np.array([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
assert check_neighbours(1, 1, a) == 8
def test_init_board():
board = init_board(10, 10)
assert board.shape[0] == 10 and board.shape[1] == 10
board = init_board(100, 10)
assert board.shape[0] == 100 and board.shape[1] == 10
board = init_board(10, 100)
assert board.shape[0] == 10 and board.shape[1] == 100
def test_get_next_board():
a = np.array([[0, 0, 0, 0],
[1, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]])
b = np.array([[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 0]])
assert np.array_equal(get_next_board(a), b)
a = np.array([[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]])
b = np.array([[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]])
assert np.array_equal(get_next_board(a), b)
def test_read_board():
board = read_board("square.board")
true_board = np.array([[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]])
np.array_equal(board, true_board)