-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
129 lines (109 loc) · 3.4 KB
/
main_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
package main
import (
//"bytes"
//"encoding/json"
//"file/filepath"
//"fmt"
//"os"
//"strings"
//"fmt"
"testing"
)
var board2x2 = [][]byte{{'b', 'a'}, {'r', 't'}}
var board3x3 = [][]byte{{'b', 'a', 'e'}, {'r', 't', 'm'}, {'z', 'z', 'z'}}
/*
0 1 2 3
1 - - -
2 - - -
3 - - -
*/
var adjacent_testcases = []struct {
start *Coord
max *Coord
expecting []*Coord
}{
{Row0Col0, BoardMax2x2, []*Coord{Row0Col1, Row1Col0, Row1Col1}},
{Row0Col0, BoardMax3x3, []*Coord{Row0Col1, Row1Col0, Row1Col1}},
{Row0Col0, BoardMax4x4, []*Coord{Row0Col1, Row1Col0, Row1Col1}},
{Row0Col1, BoardMax2x2, []*Coord{Row0Col0, Row1Col0, Row1Col1}},
{Row0Col1, BoardMax3x3, []*Coord{Row0Col0, Row0Col2, Row1Col0, Row1Col1, Row1Col2}},
{Row0Col1, BoardMax4x4, []*Coord{Row0Col0, Row0Col2, Row1Col0, Row1Col1, Row1Col2}},
{Row0Col2, BoardMax3x3, []*Coord{Row0Col1, Row1Col1, Row1Col2}},
{Row0Col2, BoardMax4x4, []*Coord{Row0Col1, Row0Col3, Row1Col1, Row1Col2, Row1Col3}},
{Row0Col3, BoardMax4x4, []*Coord{Row0Col2, Row1Col2, Row1Col3}},
{Row1Col0, BoardMax2x2, []*Coord{Row0Col0, Row0Col1, Row1Col1}},
{Row1Col0, BoardMax3x3, []*Coord{Row0Col0, Row0Col1, Row1Col1, Row2Col0, Row2Col1}},
{Row1Col0, BoardMax4x4, []*Coord{Row0Col0, Row0Col1, Row1Col1, Row2Col0, Row2Col1}},
}
var board_testcases = []struct {
board [][]byte
expectations map[string]bool
}{
{board2x2, map[string]bool{"bar": true, "bart": true, "barb": false, "back": false, "barth": false, "rath": false, "rat": true}},
{board3x3, map[string]bool{"bar": true, "bart": true, "barb": false, "back": false, "barth": false, "rath": false, "rat": true, "tram": true, "zz": true, "zzz": true, "zzzz": false}},
}
func TestBoards(t *testing.T) {
for _, tc := range board_testcases {
for test, expected := range tc.expectations {
actual := boggleHasWord(tc.board, test, &Solution{})
if actual != expected {
t.Logf("Expected test [%v] to have result %v", test, expected)
t.Fail()
} else {
if actual {
t.Logf("Success: Found test word [%v]\n", test)
} else {
t.Logf("Success: Did not find test word [%v]\n", test)
}
}
}
}
}
func TestAdjacents(t *testing.T) {
for _, tc := range adjacent_testcases {
actual := getAdjacents(tc.start, tc.max)
if !match(actual, tc.expecting) {
t.Logf("Starting at coord %+v and expecting %+v, but found %+v", tc.start, tc.expecting, actual)
t.Fail()
}
}
}
func match(actual, expectation []*Coord) bool {
if len(actual) != len(expectation) {
return false
}
outer:
for _, a := range actual {
for _, e := range expectation {
if e.x == a.x && e.y == a.y {
continue outer
}
}
return false
}
return true
}
//func boggleHasWord(board [][]byte, word string, solution *Solution) bool {
//func getEntireBoard(max *Coord) []*Coord {
//func getAdjacents(current, max *Coord) []*Coord {
var (
Row0Col0 *Coord = &Coord{x: 0, y: 0}
Row0Col1 = &Coord{x: 0, y: 1}
Row0Col2 = &Coord{x: 0, y: 2}
Row0Col3 = &Coord{x: 0, y: 3}
Row1Col0 = &Coord{x: 1, y: 0}
Row1Col1 = &Coord{x: 1, y: 1}
Row1Col2 = &Coord{x: 1, y: 2}
Row1Col3 = &Coord{x: 1, y: 3}
Row2Col0 = &Coord{x: 2, y: 0}
Row2Col1 = &Coord{x: 2, y: 1}
Row2Col2 = &Coord{x: 2, y: 2}
Row2Col3 = &Coord{x: 2, y: 3}
Row3Col0 = &Coord{x: 3, y: 0}
Row3Col1 = &Coord{x: 3, y: 1}
Row3Col2 = &Coord{x: 3, y: 2}
Row3Col3 = &Coord{x: 3, y: 3}
BoardMax2x2 = Row1Col1
BoardMax3x3 = Row2Col2
BoardMax4x4 = Row3Col3
)