-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation_test.go
66 lines (59 loc) · 1.59 KB
/
validation_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
package battleword
import "testing"
func TestValidGuess(t *testing.T) {
guess := "beast"
answer := "beast"
valid := ValidGuess(guess, answer)
if !valid {
t.FailNow()
}
}
type ResultTestCase struct {
guess string
answer string
result []int
}
var (
resultTestCases = []ResultTestCase{
{"beast", "beast", []int{2, 2, 2, 2, 2}},
{"least", "beast", []int{0, 2, 2, 2, 2}},
{"beast", "beasy", []int{2, 2, 2, 2, 0}},
{"trees", "beast", []int{1, 0, 1, 0, 1}},
{"trees", "ulcer", []int{0, 1, 0, 2, 0}},
{"ruler", "ulcer", []int{0, 1, 1, 2, 2}},
{"bluer", "ulcer", []int{0, 2, 1, 2, 2}},
{"seers", "ulcer", []int{0, 1, 0, 1, 0}},
{"seers", "ulcee", []int{0, 1, 1, 0, 0}},
{"seerse", "elceec", []int{0, 1, 1, 0, 0, 1}},
{"golly", "bosom", []int{0, 2, 0, 0, 0}},
{"bosom", "golly", []int{0, 2, 0, 0, 0}},
{"bisom", "golly", []int{0, 0, 0, 1, 0}},
}
)
func TestGetResults(t *testing.T) {
for _, testCase := range resultTestCases {
result := GetResult(testCase.guess, testCase.answer)
// compare each character in the result
for i := 0; i < len(result); i++ {
if result[i] != testCase.result[i] {
t.Logf(
"got mismatch. guess: %s, answer %s, result %+v, expected result %+v",
testCase.guess,
testCase.answer,
result,
testCase.result,
)
t.FailNow()
}
}
}
}
// BenchmarkGetResults tests iterations of all test cases.
// may want to add one benchmark for each test in the future.
func BenchmarkGetResults(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, testCase := range resultTestCases {
GetResult(testCase.guess, testCase.answer)
}
}
}