/
gol_test.go
67 lines (60 loc) · 1.8 KB
/
gol_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
package main
import "testing"
import "gol"
func TestAliveCell(t *testing.T) {
cell := gol.NewCell(true)
if (cell.Next(1).IsAlive()) {
t.Fatal("Alive cell with 1 neighbour should die")
}
if (!cell.Next(2).IsAlive()) {
t.Fatal("Alive cell with 2 neighbour should not die")
}
if (!cell.Next(3).IsAlive()) {
t.Fatal("Alive cell with 3 neighbour should not die")
}
}
func TestDeadCell(t *testing.T) {
cell := gol.NewCell(false)
if (cell.Next(1).IsAlive()) {
t.Fatal("Dead cell with 1 neighbour should stay dead")
}
if (cell.Next(4).IsAlive()) {
t.Fatal("Dead cell with 4 neighbour should stay dead")
}
if (cell.Next(5).IsAlive()) {
t.Fatal("Dead cell with 5 neighbour should stay dead")
}
if (!cell.Next(3).IsAlive()) {
t.Fatal("Dead cell with 3 neighbour should become alive")
}
}
func TestBoard(t *testing.T) {
board := gol.NewBoard()
board.SetAlive(gol.NewPoint(2,3))
board.SetAlive(gol.NewPoint(0,3))
if (!board.GetCell(gol.NewPoint(2,3)).IsAlive()) {
t.Fatal("Expected alive cell on 2,3")
}
if (board.AliveNeighbors(gol.NewPoint(1,3)) != 2) {
t.Fatal("Expected neighbors for 1,3 is 2")
}
if (board.AliveNeighbors(gol.NewPoint(3,3)) != 1) {
t.Fatal("Expected neighbors for 3,3 is 1")
}
}
func TestNextBoard(t *testing.T) {
board := gol.NewBoard()
board.SetAlive(gol.NewPoint(1,2))
board.SetAlive(gol.NewPoint(2,2))
board.SetAlive(gol.NewPoint(3,2))
next := board.Next()
if (!next.GetCell(gol.NewPoint(2,1)).IsAlive()) {
t.Fatal("Expected alive cell on 2,1")
}
if (!next.GetCell(gol.NewPoint(2,2)).IsAlive()) {
t.Fatal("Expected alive cell on 2,2")
}
if (!next.GetCell(gol.NewPoint(2,3)).IsAlive()) {
t.Fatal("Expected alive cell on 2,3")
}
}