-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_test.go
67 lines (58 loc) · 1.42 KB
/
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
package gotak
import (
"fmt"
"io/ioutil"
"path"
"testing"
)
func assertNotEqual(t *testing.T, context string, a interface{}, b interface{}) {
if a == b {
t.Errorf("%s: %+v == %+v", context, a, b)
}
}
func TestParse(t *testing.T) {
dir := path.Join(".", "test_games")
files, err := ioutil.ReadDir(dir)
if err != nil {
t.Errorf("%+v", err)
}
for _, fi := range files {
// Run the following test for each file
t.Run(fi.Name(), func(t *testing.T) {
file, err := ioutil.ReadFile(fmt.Sprintf("test_games/%s", fi.Name()))
if err != nil {
t.Errorf("%s: %+v", fi.Name(), err)
}
g, err := ParsePTN(file)
if err != nil {
t.Errorf("%+v", err)
}
// Required tags
for _, k := range []string{"Player1", "Player2", "Date", "Size", "Result"} {
_, err := g.GetMeta(k)
if err != nil {
t.Errorf("%+v", err)
}
}
for _, turn := range g.Turns {
context := fmt.Sprintf("Turn: %+v", turn)
assertNotEqual(t, context, turn, nil)
assertNotEqual(t, context, turn.First, nil)
assertNotEqual(t, context, turn.Second, nil)
assertNotEqual(t, context, turn.First.Text, "")
assertNotEqual(t, context, turn.Second.Text, "")
assertNotEqual(t, context, turn.Number, 0)
}
})
}
}
func TestGameOver(t *testing.T) {
game, err := NewGame(6, 1, "test")
if err != nil {
t.Errorf("%+v", err)
}
_, over := game.GameOver()
if over {
t.Errorf("Game over on empty board")
}
}