-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice_test.go
89 lines (84 loc) · 1.4 KB
/
slice_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
package gods
import "testing"
func TestEqual(t *testing.T) {
for _, test := range []struct {
Label string
L []int
R []int
Equal bool
}{
{
Label: "empty",
L: []int{},
R: []int{},
Equal: true,
},
{
Label: "differing sizes",
L: []int{},
R: []int{1},
Equal: false,
},
{
Label: "same size different members",
L: []int{1, 2},
R: []int{2, 1},
Equal: false,
},
{
Label: "equal single",
L: []int{1},
R: []int{1},
Equal: true,
},
{
Label: "equal multiple",
L: []int{1, 2},
R: []int{1, 2},
Equal: true,
},
} {
t.Run(test.Label, func(t *testing.T) {
if Equal(test.L, test.R) != test.Equal {
t.Fatalf("L: %#v R: %#v", test.L, test.R)
}
})
}
}
func TestReverse(t *testing.T) {
for _, test := range []struct {
Label string
In []int
Out []int
}{
{
Label: "empty",
In: []int{},
Out: []int{},
},
{
Label: "one",
In: []int{1},
Out: []int{1},
},
{
Label: "two",
In: []int{1, 2},
Out: []int{2, 1},
},
{
Label: "three",
In: []int{1, 2, 3},
Out: []int{3, 2, 1},
},
} {
t.Run(test.Label, func(t *testing.T) {
orig := make([]int, len(test.In))
copy(orig, test.In)
Reverse(test.In)
if !Equal(test.In, test.Out) {
t.Fatalf("got %#v from orig %#v, expected %#v", test.In, orig, test.Out)
}
})
}
}