-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathslice_test.go
63 lines (56 loc) · 1.52 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
package goutils
import "testing"
func TestIsEqualStringSlice(t *testing.T) {
s1 := []string{"a", "b", "c"}
s2 := []string{"a", "b", "c"}
s3 := []string{"a", "d", "c"}
if !IsEqualStringSlice(s1, s2) {
t.Error("s1 == s2, should return true")
}
if IsEqualStringSlice(s1, s3) {
t.Error("s1 != s3, should return false")
}
}
func TestRemoveStringSliceItemByIndex(t *testing.T) {
rawStrSlice := []string{"0", "1", "2", "3"}
newStrSlice := RemoveStringSliceItemByIndex(rawStrSlice, 1)
expectResult := []string{"0", "2", "3"}
if !IsEqualStringSlice(newStrSlice, expectResult) {
t.Error("RemoveStringSliceItemByIndex return wrong result:", "raw:", rawStrSlice, "new:", newStrSlice)
}
}
func TestChunkFloat64Slice(t *testing.T) {
raw := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}
result := ChunkFloat64Slice(raw, 3)
if len(result) != 3 {
t.Error("chunk 3 error", result)
}
result = ChunkFloat64Slice(raw, 4)
if len(result) != 3 {
t.Error("chunk 4 error", result)
}
result = ChunkFloat64Slice(raw, 5)
if len(result) != 2 {
t.Error("chunk 5 error", result)
}
}
func TestIsStrInSlice(t *testing.T) {
r := IsStrInSlice("asd", []string{"xx", "aa", "xasd"})
if r == true {
t.Error("should return false")
}
r = IsStrInSlice("asd", []string{"xx", "aa", "asd"})
if r == false {
t.Error("should return true")
}
}
func TestIsIntInSlice(t *testing.T) {
r := IsIntInSlice(1, []int{7, 30})
if r == true {
t.Error("should return false")
}
r = IsIntInSlice(2, []int{2, 3, 4})
if r == false {
t.Error("should return true")
}
}