-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgosudoku_test.go
More file actions
131 lines (114 loc) · 3.11 KB
/
Copy pathgosudoku_test.go
File metadata and controls
131 lines (114 loc) · 3.11 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"reflect"
"testing"
)
const (
simple = "..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3.."
harder = "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......"
diagonal1 = "2.............62....1....7...6..8...3...9...7...6..4...4....8....52.............3"
diagonal2 = "4.......3..9.........1...7.....1.8.....5.9.....1.2.....3...5.........7..7.......8"
)
func TestStandardSudokuBoardInit(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else {
board := NewSudoku(simple, STANDARD)
if unitsLength := len(board.allUnits); unitsLength != 27 {
t.Error("Standard Sudoku board should test 27 units")
}
}
}
func TestDiagonalSudokuBoardInit(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else {
board := NewSudoku(diagonal1, DIAGONAL)
if unitsLength := len(board.allUnits); unitsLength != 29 {
t.Error("Diagonal Sudoku board should test 29 units")
}
}
}
func TestUnitsByCell(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else {
board := NewSudoku(simple, STANDARD)
if unitsLength := len(board.unitsByCell); unitsLength != len(BOXES) {
t.Error("Incorrect number of units in unitsByCell")
}
unitsA1 := board.unitsByCell["A1"]
foundRow := false
foundCol := false
for i := range unitsA1 {
if reflect.DeepEqual(unitsA1[i], board.rowUnits[0]) {
foundRow = true
}
if reflect.DeepEqual(unitsA1[i], board.colUnits[0]) {
foundCol = true
}
}
if !foundRow || !foundCol {
t.Error("Units for A1 does not include one of either row A or col 1 units")
}
}
}
func TestPeersByCell(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else {
board := NewSudoku(simple, STANDARD)
if unitsLength := len(board.peersByCell); unitsLength != len(BOXES) {
t.Error("Incorrect number of units in peersByCell")
}
peersA1 := board.peersByCell["A1"]
foundA9 := false
foundI1 := false
for i := range peersA1 {
if peersA1[i] == "A9" {
foundA9 = true
}
if peersA1[i] == "I1" {
foundI1 = true
}
}
if !foundA9 || !foundI1 {
t.Error("Peers for A1 does not include one of either A9 or I1")
}
}
}
func TestValues(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else {
board := NewSudoku(simple, STANDARD)
if unitsLength := len(board.values); unitsLength != len(BOXES) {
t.Error("Incorrect number of values in peersByCell")
}
}
}
func TestDeepCopy(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else {
board := NewSudoku(simple, STANDARD)
board2 := board.Copy()
board2.values["A1"] = CellValue{Value: "4", Source: RESOLVED}
if board.values["A1"] == board2.values["A1"] {
t.Error("Board is not deep copied")
}
}
}
func TestSolve(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else {
board := NewSudoku(simple, STANDARD)
resultBoard, success := board.Solve()
if !success {
t.Error("Board was not solved")
} else {
resultBoard.Print()
}
}
}