-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_game_test.go
156 lines (124 loc) · 3.08 KB
/
make_game_test.go
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package gol
import "testing"
// MakeGame testing
// Checking that permutations of the rules work
var opts = Options{
0,
0,
[][]uint8{},
0,
Rules{}}
var copyOpts Options
func TestDefaultLoad(t *testing.T) {
copyOpts = opts
game := MakeGame(copyOpts)
if game.X != 50 {
t.Fatalf("X Coordinate not set to default of 50")
}
if game.Y != 50 {
t.Fatalf("Y Coordinate not set to default of 50")
}
if len(game.Rules.Array) > 6 || len(game.Rules.Array) < 2 {
t.Fatalf("Random rule number not within 2-6")
}
}
func TestGridLoad(t *testing.T) {
copyOpts = opts
copyOpts.Grid = MakeGrid(4, 3)
game := MakeGame(copyOpts)
if game.X != 4 {
t.Fatalf("X Coordinate not set to 4")
}
if game.Y != 3 {
t.Fatalf("Y Coordinate not set to 3")
}
}
func TestGridXYSet(t *testing.T) {
copyOpts = opts
copyOpts.Y = 3
copyOpts.X = 4
game := MakeGame(copyOpts)
if len(game.Field.Front[0]) != 4 {
t.Fatalf("X Coordinate not set to 4")
}
if len(game.Field.Front) != 3 {
t.Fatalf("Y Coordinate not set to 3")
}
}
func TestRulesLoad(t *testing.T) {
copyOpts = opts
copyOpts.Rules = Rules{}
copyOpts.Rules.Randomize(3)
game := MakeGame(copyOpts)
if len(game.Rules.Array) != 3 {
t.Fatalf("Three rules loaded and not retained")
}
}
func TestRulenumberSet(t *testing.T) {
copyOpts = opts
copyOpts.RuleNumber = 3
game := MakeGame(copyOpts)
if len(game.Rules.Array) != 3 {
t.Fatalf("Rulenumber 3 set and not created")
}
}
func TestGridvsXYMismatch(t *testing.T) {
copyOpts = opts
copyOpts.Grid = MakeGrid(4, 3)
copyOpts.X = 10
copyOpts.Y = 10
defer func() {
if r := recover(); r == nil {
t.Errorf("A mismatch between grid size and set X and Y did not cause an error")
}
}()
MakeGame(copyOpts)
}
func TestRulesvsRulenumberMismatch(t *testing.T) {
copyOpts = opts
copyOpts.Rules = Rules{}
copyOpts.Rules.Randomize(3)
copyOpts.RuleNumber = 10
defer func() {
if r := recover(); r == nil {
t.Errorf("A mismatch between rules size and rulenumber did not cause an error")
}
}()
MakeGame(copyOpts)
}
func TestRulesvsGridContentMismatch(t *testing.T) {
copyOpts = opts
copyOpts.Rules = Rules{}
copyOpts.Rules.Randomize(3)
copyOpts.Grid = MakeGrid(3, 3)
copyOpts.Grid[0][0] = 8
defer func() {
if r := recover(); r == nil {
t.Errorf("A mismatch between rules size and the grid content did not cause an error")
}
}()
MakeGame(copyOpts)
}
func TestAlivesFromGrid(t *testing.T) {
copyOpts = opts
copyOpts.Rules = Rules{}
copyOpts.Rules.Randomize(2)
copyOpts.Rules.Array[0].Alive = false
copyOpts.Rules.Array[1].Alive = true
y0 := []uint8{0, 0, 0, 0, 0}
y1 := []uint8{0, 0, 1, 0, 0}
y2 := []uint8{0, 0, 1, 0, 0}
y3 := []uint8{0, 0, 1, 0, 0}
y4 := []uint8{0, 0, 0, 0, 0}
copyOpts.Grid = [][]uint8{y0, y1, y2, y3, y4}
game := MakeGame(copyOpts)
ey0 := []uint8{0, 1, 1, 1, 0}
ey1 := []uint8{0, 2, 1, 2, 0}
ey2 := []uint8{0, 3, 2, 3, 0}
ey3 := []uint8{0, 2, 1, 2, 0}
ey4 := []uint8{0, 1, 1, 1, 0}
eArray := [][]uint8{ey0, ey1, ey2, ey3, ey4}
if mismatchCheck(eArray, game.aliveCount.Front) {
t.Fatalf("Generated field of alives not matching expected")
}
}