58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package horsepaste
|
|
|
|
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)
|
|
}
|
|
}
|