-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex_test.go
51 lines (47 loc) · 862 Bytes
/
index_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
package refutil
import (
"testing"
)
func TestSearchIndex(t *testing.T) {
arr := []uint{1, 2, 3}
data := NewData(arr)
index := data.SearchIndex(Equal, uint(2))
if index != 1 {
t.Fatal()
}
index = data.SearchIndex(Equal, 2)
if index != 1 {
t.Fatal()
}
index = data.SearchIndex(Equal, nil)
if index != -1 {
t.Fatal()
}
data = NewData(nil)
index = data.SearchIndex(Equal, nil)
if index != -1 {
t.Fatal()
}
defer func() {
if r := recover(); r != ErrArgumentNotIndexable {
t.Fatal()
}
}()
data = NewData("")
data.SearchIndex(Equal, 1)
}
func TestSearchIndex2(t *testing.T) {
arr := []uint{1, 2, 3}
if i := Index(arr, 1); i != 0 {
t.Fatal()
}
}
func TestSearchIndexSame(t *testing.T) {
arr := []uint{1, 2, 3}
if i := IndexSame(arr, 1); i != -1 {
t.Fatal()
}
if i := IndexSame(arr, uint(0)); i != -1 {
t.Fatal()
}
}