-
Notifications
You must be signed in to change notification settings - Fork 0
/
slices_test.go
99 lines (79 loc) · 2.36 KB
/
slices_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
package slices
import (
"reflect"
"testing"
strslices "github.com/12yanogden/go-strslices"
)
func TestRemoveBeginning(t *testing.T) {
slice := []string{"a", "b", "c", "d"}
expected := []string{"b", "c", "d"}
actual := Remove(slice, 0)
if !strslices.Equals(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v", expected, actual)
}
}
func TestRemoveMiddle(t *testing.T) {
slice := []string{"a", "b", "c", "d"}
expected := []string{"a", "b", "d"}
actual := Remove(slice, 2)
if !strslices.Equals(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v", expected, actual)
}
}
func TestRemoveEnd(t *testing.T) {
slice := []string{"a", "b", "c", "d"}
expected := []string{"a", "b", "c"}
actual := Remove(slice, (len(slice) - 1))
if !strslices.Equals(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v", expected, actual)
}
}
func TestRemoveEmpty(t *testing.T) {
slices := [][]string{{}, {"a", "b"}, {}, {"c"}, {}}
expected := [][]string{{"a", "b"}, {"c"}}
actual := RemoveEmpty(slices)
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v", expected, actual)
}
}
func TestPrepend(t *testing.T) {
slice := []string{"b", "c"}
item := "a"
expected := []string{"a", "b", "c"}
actual := Prepend(slice, item)
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v", expected, actual)
}
}
func TestShiftWithEmpty(t *testing.T) {
slice := []string{}
expected := []string{}
actual := Shift[string](slice)
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v", expected, actual)
}
}
func TestShiftWithOne(t *testing.T) {
slice := []string{"item"}
expected := []string{}
actual := Shift[string](slice)
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v", expected, actual)
}
}
func TestShiftWithMany(t *testing.T) {
slice := []string{"item1", "item2"}
expected := []string{"item2"}
actual := Shift[string](slice)
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v", expected, actual)
}
}
func TestIndexes(t *testing.T) {
slice := []string{"item1", "item2", "item3", "item4", "item5"}
expected := []int{0, 1, 2, 3, 4}
actual := Indexes(slice)
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\nExpected:\t%#v\nActual:\t\t%#v\n", expected, actual)
}
}