/
main_test.go
70 lines (64 loc) · 1.32 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
package main
import (
"testing"
)
func TestGetNumberOfPossibleNumbers(t *testing.T) {
tables := []struct {
position int
length int
result int
}{
{4, 0, 0},
{4, 3, 6},
{1, 3, 5},
{2, 3, 4},
{0, 2, 2},
}
for _, table := range tables {
actualResult := GetNumberOfPossibleNumbers(table.position, table.length)
if table.result != actualResult {
t.Errorf("getNumberOfPossibleNumbers(%d, %d) was incorrect. Got %d, want %d\n", table.position, table.length, actualResult, table.result)
}
}
}
func TestGetMoves(t *testing.T) {
tables := []struct {
num int
result []int
}{
{0, []int{4, 6}},
{1, []int{6, 8}},
{2, []int{7, 9}},
{3, []int{4, 8}},
{4, []int{3, 9, 0}},
{5, nil},
{6, []int{1, 7, 0}},
{7, []int{2, 6}},
{8, []int{1, 3}},
{9, []int{2, 4}},
{10, nil},
}
for _, table := range tables {
actualResult := GetMoves(table.num)
if equals(table.result, actualResult) == false {
t.Errorf("getMoves(%d) was incorrect. Got %v, want %v\n", table.num, actualResult, table.result)
}
}
}
func equals(sliceA, sliceB []int) bool {
if sliceA == nil && sliceB == nil {
return true
}
if sliceA == nil || sliceB == nil {
return false
}
if len(sliceA) != len(sliceB) {
return false
}
for i := range sliceA {
if sliceA[i] != sliceB[i] {
return false
}
}
return true
}