-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator_test.go
87 lines (76 loc) · 3.88 KB
/
validator_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
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 godoku
import (
"testing"
)
func TestValidate(t *testing.T) {
solved := []byte{4, 3, 5, 2, 6, 9, 7, 8, 1, 6, 8, 2, 5, 7, 1, 4, 9, 3, 1, 9, 7, 8, 3, 4, 5, 6, 2, 8, 2, 6, 1, 9, 5, 3, 4, 7, 3, 7, 4, 6, 8, 2, 9, 1, 5, 9, 5, 1, 7, 4, 3, 6, 2, 8, 5, 1, 9, 3, 2, 6, 8, 7, 4, 2, 4, 8, 9, 5, 7, 1, 3, 6, 7, 6, 3, 4, 1, 8, 2, 5, 9}
result := Validate(&solved, 9)
if !result {
t.Error("Failed a correct gameboard.")
}
solved = []byte{4, 3, 5, 2, 6, 9, 7, 8, 1, 6, 8, 2, 5, 7, 1, 4, 9, 3, 1, 9, 7, 8, 3, 4, 5, 6, 2, 8, 2, 6, 1, 9, 5, 3, 4, 7, 3, 7, 4, 6, 8, 2, 9, 1, 5, 9, 1, 1, 7, 4, 3, 6, 2, 8, 5, 1, 9, 3, 2, 6, 8, 7, 4, 2, 4, 8, 9, 5, 7, 1, 3, 6, 7, 6, 3, 4, 1, 8, 2, 5, 9}
result = Validate(&solved, 9)
if result {
t.Error("Validated an invalid gameboard.")
}
solved = []byte{5, 9, 6, 2, 1, 5, 5, 3, 2, 8, 3, 4, 6, 4, 7, 8, 9, 6, 2, 7, 1, 3, 9, 8, 1, 7, 4, 4, 1, 8, 9, 6, 1, 4, 1, 3, 9, 6, 7, 8, 3, 4, 2, 5, 8, 3, 5, 2, 5, 7, 2, 9, 6, 7, 1, 8, 9, 4, 2, 3, 3, 4, 5, 6, 2, 3, 7, 8, 9, 6, 2, 9, 7, 4, 5, 1, 5, 6, 7, 8, 1}
result = Validate(&solved, 9)
if result {
t.Error("Validated an invalid gameboard.")
}
}
func TestValidateRows(t *testing.T) {
solved := []byte{4, 3, 5, 2, 6, 9, 7, 8, 1, 6, 8, 2, 5, 7, 1, 4, 9, 3, 1, 9, 7, 8, 3, 4, 5, 6, 2, 8, 2, 6, 1, 9, 5, 3, 4, 7, 3, 7, 4, 6, 8, 2, 9, 1, 5, 9, 5, 1, 7, 4, 3, 6, 2, 8, 5, 1, 9, 3, 2, 6, 8, 7, 4, 2, 4, 8, 9, 5, 7, 1, 3, 6, 7, 6, 3, 4, 1, 8, 2, 5, 9}
result := validateRows(&solved, 9)
if !result {
t.Error("Valid Solution. Expected result to be true")
}
solved = []byte{4, 3, 5, 2, 6, 9, 7, 8, 1, 6, 8, 2, 5, 7, 1, 4, 9, 3, 1, 9, 7, 8, 3, 4, 5, 6, 2, 8, 2, 6, 1, 9, 5, 3, 4, 7, 3, 7, 4, 6, 8, 2, 9, 1, 5, 9, 1, 1, 7, 4, 3, 6, 2, 8, 5, 1, 9, 3, 2, 6, 8, 7, 4, 2, 4, 8, 9, 5, 7, 1, 3, 6, 7, 6, 3, 4, 1, 8, 2, 5, 9}
result = validateRows(&solved, 9)
if result {
t.Error("Invalid Solution. Expected result to be false")
}
}
func TestValidateColumns(t *testing.T) {
solved := []byte{4, 3, 5, 2, 6, 9, 7, 8, 1, 6, 8, 2, 5, 7, 1, 4, 9, 3, 1, 9, 7, 8, 3, 4, 5, 6, 2, 8, 2, 6, 1, 9, 5, 3, 4, 7, 3, 7, 4, 6, 8, 2, 9, 1, 5, 9, 5, 1, 7, 4, 3, 6, 2, 8, 5, 1, 9, 3, 2, 6, 8, 7, 4, 2, 4, 8, 9, 5, 7, 1, 3, 6, 7, 6, 3, 4, 1, 8, 2, 5, 9}
result := validateColums(&solved, 9)
if !result {
t.Error("Valid Solution. Expected result to be true")
}
solved = []byte{4, 3, 5, 2, 6, 9, 7, 8, 1, 6, 8, 2, 5, 7, 1, 4, 9, 3, 1, 9, 7, 8, 3, 4, 5, 6, 2, 8, 2, 6, 1, 9, 5, 3, 4, 7, 3, 7, 4, 6, 8, 2, 9, 1, 5, 9, 1, 1, 7, 4, 3, 6, 2, 8, 5, 1, 9, 3, 2, 6, 8, 7, 4, 2, 4, 8, 9, 5, 7, 1, 3, 6, 7, 6, 3, 4, 1, 8, 2, 5, 9}
result = validateColums(&solved, 9)
if result {
t.Error("Invalid Solution. Expected result to be false")
}
}
func TestValidateBlocks(t *testing.T) {
solved := []byte{4, 3, 5, 2, 6, 9, 7, 8, 1, 6, 8, 2, 5, 7, 1, 4, 9, 3, 1, 9, 7, 8, 3, 4, 5, 6, 2, 8, 2, 6, 1, 9, 5, 3, 4, 7, 3, 7, 4, 6, 8, 2, 9, 1, 5, 9, 5, 1, 7, 4, 3, 6, 2, 8, 5, 1, 9, 3, 2, 6, 8, 7, 4, 2, 4, 8, 9, 5, 7, 1, 3, 6, 7, 6, 3, 4, 1, 8, 2, 5, 9}
result := validateBlocks(&solved, 9)
if !result {
t.Error("Valid Solution. Expected result to be true")
}
solved = []byte{4, 3, 5, 2, 6, 9, 7, 8, 1, 6, 8, 2, 5, 7, 1, 4, 9, 3, 1, 9, 7, 8, 3, 4, 5, 6, 2, 8, 2, 6, 1, 9, 5, 3, 4, 7, 3, 7, 4, 6, 8, 2, 9, 1, 5, 9, 1, 1, 7, 4, 3, 6, 2, 8, 5, 1, 9, 3, 2, 6, 8, 7, 4, 2, 4, 8, 9, 5, 7, 1, 3, 6, 7, 6, 3, 4, 1, 8, 2, 5, 9}
result = validateBlocks(&solved, 9)
if result {
t.Error("Invalid Solution. Expected result to be false")
}
}
func TestValidateRow(t *testing.T) {
row := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}
result := validate(&row, 9)
if !result {
t.Error("Failed. result should have been true")
}
row2 := []byte{1, 1, 2, 3, 4, 5, 6, 7, 8}
result = validate(&row2, 9)
if result {
t.Error("Failed. result should have been false")
}
//non valid
//4 2 8 6 8 1 7 2 9
row = []byte{4, 2, 8, 6, 8, 1, 7, 2, 9}
result = validate(&row, 9)
if result {
t.Error("Failed. result should have been false")
}
}