-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_test.go
60 lines (50 loc) · 1.26 KB
/
puzzle_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
package sudoku_test
import (
"testing"
"github.com/curlymon/sudoku"
)
func TestEasyPuzzle(t *testing.T) {
testNewPuzzleFromStateFile(t, "./fixtures/easy.json")
}
func TestHardPuzzle(t *testing.T) {
testNewPuzzleFromStateFile(t, "./fixtures/hard.json")
}
func testNewPuzzleFromStateFile(t *testing.T, stateFile string) {
state, err := sudoku.LoadStateFromFile(stateFile)
if err != nil {
t.Fatal(err)
}
t.Logf("Start State:\n%s", state)
p, err := sudoku.NewPuzzleFromState(state)
if err != nil {
t.Fatal(err)
}
if !p.IsSolved() {
t.Log("attempting recursive solve")
p, err = sudoku.Solve(p)
if err != nil {
t.Errorf("error solving: %s\n%v", err, p)
}
}
afterSolveState, _ := p.State()
t.Logf("End State:%s", afterSolveState)
}
func BenchmarkEasyyPuzzle(b *testing.B) {
benchmarkNewPuzzleFromStateFile(b, "./fixtures/easy.json")
}
func BenchmarkHardPuzzle(b *testing.B) {
benchmarkNewPuzzleFromStateFile(b, "./fixtures/hard.json")
}
func benchmarkNewPuzzleFromStateFile(b *testing.B, stateFile string) {
state, err := sudoku.LoadStateFromFile(stateFile)
if err != nil {
b.Fatal(err)
}
b.RunParallel(func(pb *testing.PB) {
var p *sudoku.Puzzle
for pb.Next() {
p, _ = sudoku.NewPuzzleFromState(state)
p, _ = sudoku.Solve(p)
}
})
}