-
Notifications
You must be signed in to change notification settings - Fork 1
/
constants_test.go
67 lines (58 loc) · 1.88 KB
/
constants_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 gridspech_test
import (
"testing"
gs "github.com/deanveloper/gridspech-go"
)
// has every TileType, and all are valid
const validTestGrid = `
1m2 1e 0 1e 0
1 _ 0 1 0
1 1/ 1/ 1 0
0 0 0 0 0
0 0 0 2k 0
0 0 0 2j1 0
2 2m2 0 0 0
2m1 2k 0 0 0
`
// has every TileType, and all are invalid
const invalidTestGrid = `
2j1 2/j1 2j1 1e 1
0 _ 0 1e 0
0m2 0 0 0 0
0m1 0 0 0 0
0m2 1 0 0 1
0 0 0 1 0j1
2 0 0 1k 0
0k 2 0 0 1
`
// MakeValidGrid returns a grid which contains a tile of every single Type and Color,
// and all tiles are valid.
func MakeValidGrid() gs.Grid {
return gs.MakeGridFromString(validTestGrid, 3)
}
// MakeInvalidGrid returns a grid which contains a tile of every single Type and Color,
// and all non-blank and non-hole tiles are invalid.
func MakeInvalidGrid() gs.Grid {
return gs.MakeGridFromString(invalidTestGrid, 3)
}
// TestMakeGridFromString tests creating a grid from a string.
func TestMakeGridFromString(t *testing.T) {
tiles := MakeValidGrid().Tiles
cases := []struct {
Actual, Expected gs.TileData
}{
{tiles[0][0].Data, gs.TileData{Type: gs.TypeDot1, Color: 2}},
{tiles[0][1].Data, gs.TileData{Type: gs.TypeBlank, Color: 2}},
{tiles[1][0].Data, gs.TileData{Type: gs.TypeCrown, Color: 2}},
{tiles[1][1].Data, gs.TileData{Type: gs.TypeDot2, Color: 2}},
{tiles[1][7].Data, gs.TileData{Type: gs.TypeGoal, Color: 1}},
{tiles[1][6].Data, gs.TileData{Type: gs.TypeHole}},
{tiles[1][5].Data, gs.TileData{Type: gs.TypeBlank, Color: 1, Sticky: true}},
{tiles[3][2].Data, gs.TileData{Type: gs.TypeJoin1, Color: 2}},
}
for _, testCase := range cases {
if testCase.Expected != testCase.Actual {
t.Errorf("\nexpected: %#v\ngot: %#v\n", testCase.Expected, testCase.Actual)
}
}
}