forked from jbowens/codenames
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_test.go
58 lines (50 loc) · 1.09 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
package codenames
import (
"encoding/json"
"testing"
"github.com/jbowens/dictionary"
)
var testWords []string
func init() {
d, err := dictionary.Load("assets/original.txt")
if err != nil {
panic(err)
}
testWords = d.Words()
}
func BenchmarkGameMarshal(b *testing.B) {
b.StopTimer()
d, err := dictionary.Load("assets/original.txt")
if err != nil {
b.Fatal(err)
}
g := newGame("foo", GameState{
Seed: 1,
Round: 0,
Revealed: make([]bool, 25),
WordSet: d.Words(),
}, GameOptions{})
b.StartTimer()
for i := 0; i < b.N; i++ {
_, err = json.Marshal(g)
if err != nil {
b.Fatal(err)
}
}
}
func TestGameShuffle(t *testing.T) {
gamesWithoutRepeats := len(testWords)/25 - 1
initialState := randomState(testWords)
currState := initialState
m := map[string]int{}
for i := 0; i < gamesWithoutRepeats; i++ {
g := newGame("foo", currState, GameOptions{})
for _, w := range g.Words {
if prevI, ok := m[w]; ok {
t.Errorf("Word %q appeared twice, once in game %d and once in game %d.", w, prevI, i)
}
m[w] = i
}
currState = nextGameState(currState)
}
}