-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhint_test.go
146 lines (140 loc) · 2.64 KB
/
hint_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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package tallylogic
import (
"reflect"
"testing"
)
func Test_hintCalculator_GetHints(t *testing.T) {
tests := []struct {
name string
board TableBoard
want []Hint
wantCount int
}{
// TODO: Add test cases.
{
"Get simple hints",
TableBoard{
cells: cellCreator(
0, 0, 3,
1, 2, 3,
0, 0, 0,
),
rows: 3,
columns: 3,
},
[]Hint{
{
Value: 6,
Method: EvalMethodSum,
Path: []int{5, 2},
},
{
Value: 6,
Method: EvalMethodSum,
Path: []int{3, 4, 5},
},
},
2,
},
{
"Test for bigger board",
TableBoard{
cells: cellCreator(
6, 7, 6, 11, 14,
20, 18, 20, 8, 16,
11, 4, 18, 1, 12,
5, 11, 5, 10, 7,
10, 4, 6, 18, 4,
),
rows: 5,
columns: 5,
},
[]Hint{
{
Value: 36,
Method: EvalMethodSum,
// The bottom row , 10, 4, 6,
Path: []int{19, 18, 13, 12},
},
{
Value: 22,
Method: EvalMethodSum,
// The bottom row , 10, 4, 6,
Path: []int{22, 17, 16},
},
{
Value: 20,
Method: EvalMethodSum,
// The bottom row , 10, 4, 6,
Path: []int{22, 21, 20},
},
},
3,
},
{
"Test for stupid amount of hints",
TableBoard{
cells: cellCreator(
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
),
rows: 5,
columns: 5,
},
nil,
// This is not verified, but it seems reasonable
1626,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := &hintCalculator{
CellRetriever: &tt.board,
NeighbourRetriever: tt.board,
Evaluator: tt.board,
}
gotHints := g.GetHints()
if tt.want != nil {
wantMap := map[string]Hint{}
for _, h := range tt.want {
hash := h.Hash()
h.pathHash = hash
wantMap[h.pathHash] = h
}
if !reflect.DeepEqual(gotHints, wantMap) {
// for i, v := range gotHints {
// // t.Logf("hint %s %v", i, v)
// }
t.Errorf("hintCalculator.GetHints() = (count %d wanted %d) \ngot : %v, \nwant: %#v", len(gotHints), len(tt.want), gotHints, tt.want)
}
}
if tt.wantCount != len(gotHints) {
t.Errorf("fail gotCount %d, wantCount %d", len(gotHints), tt.wantCount)
}
})
}
}
func BenchmarkGetHints5x5ofOnes(b *testing.B) {
board := TableBoard{
cells: cellCreator(
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
),
rows: 5,
columns: 5,
}
g := &hintCalculator{
CellRetriever: &board,
NeighbourRetriever: board,
Evaluator: board,
}
for i := 0; i < b.N; i++ {
g.GetHints()
}
}