-
Notifications
You must be signed in to change notification settings - Fork 1
/
inslice_test.go
54 lines (49 loc) · 1.26 KB
/
inslice_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
package g
import (
"testing"
"time"
)
func TestInSlice(t *testing.T) {
if !IntInSlice(1, []int{1, 2, 3}) {
t.Fatal("should be found")
}
if !IntInSlice(1, []int{2, 1, 3}) {
t.Fatal("should be found")
}
if IntInSlice(4, []int{1, 2, 3}) {
t.Fatal("should be not found")
}
if IntInSlice(1, []int{}) {
t.Fatal("should be not found")
}
if Float32InSlice(0.3, []float32{0.2, 0.1}) {
t.Fatal("should be not found")
}
if !Float32InSlice(0.3, []float32{0.2, 0.3, 0.4}) {
t.Fatal("should be found")
}
if !StringInSlice("", []string{"", "123", "321"}) {
t.Fatal("should be found")
}
if !StringInSlice("123", []string{"", "123", "321"}) {
t.Fatal("should be found")
}
if StringInSlice("", []string{}) {
t.Fatal("should be not found")
}
if StringInSlice("123", []string{}) {
t.Fatal("should be not found")
}
if Complex64InSlice(0.3+0.4i, []complex64{1 + 2i, 0.3 + 0i}) {
t.Fatal("should be not found")
}
if !Complex64InSlice(0.3+0.4i, []complex64{1 + 2i, 0.3 + 0.4i}) {
t.Fatal("should be found")
}
if TimeInSlice(time.Now(), []time.Time{}) {
t.Fatal("should be not found")
}
if !TimeInSlice(time.Unix(1232141414, 32423423), []time.Time{time.Now(), time.Unix(1232141414, 32423423), time.Unix(243254365, 32452)}) {
t.Fatal("should be found")
}
}