-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcube_test.go
More file actions
87 lines (67 loc) · 1.35 KB
/
cube_test.go
File metadata and controls
87 lines (67 loc) · 1.35 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package cube
import (
"crypto/rand"
"testing"
)
// TestSpin tests the spinning move on a rubic's cube
func TestSpin(t *testing.T) {
c := NewCube()
sides:
for i := uint8(0); i < NumSides; i++ {
for j := 0; j < 4; j++ {
c.Spin(i)
}
if c != NewCube() {
t.Logf("%s\nSide %d", "TestSpin: spinning disrupted state!", i)
t.Fail()
t.Log("\n" + c.String())
c = NewCube()
continue sides
}
}
}
// TestSolved tests Rubik's Cube state test
func TestSolved(t *testing.T) {
c := NewCube()
if !c.Solved() {
t.FailNow()
}
c.Spin(0)
if c.Solved() {
t.FailNow()
}
}
// TestSolveDepth tests rubics cube solving with limited move set
func TestSolveDepth(t *testing.T) {
var cube = NewCube()
var rands = make([]uint8, 15)
rand.Read(rands)
for _, r := range rands {
cube.Spin(r % uint8(NumSides/2))
}
t.Log("\n" + cube.String())
var solution = BFSolve(cube)
for _, move := range solution {
cube.Spin(move)
}
if !cube.Solved() {
t.Log(solution)
t.Log(cube.String())
t.Fatal("Failed to solve cube!")
}
}
func testSolver(t *testing.T, s Solver) {
var cube = NewCube()
cube.Shuffle()
var solution = s(cube)
for _, move := range solution {
cube.Spin(move)
}
if !cube.Solved() {
t.Fatal("Failed to solve cube!")
}
}
// TestTwoCycleSolver tests it
func TestTwoCycleSolver(t *testing.T) {
testSolver(t, TwoCycleSolve)
}