-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch_test.go
68 lines (64 loc) · 1.06 KB
/
search_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
package refutil
import (
"testing"
)
func TestSearchValue(t *testing.T) {
kv := SearchValue([]uint{1, 2, 3}, 3)
if kv == nil {
t.Fatal()
}
if kv.Index() != 2 {
t.Fatal()
}
kv = SearchValue([]uint{1, 2, 3}, 5)
if kv != nil {
t.Fatal()
}
kv = SearchSameValue([]uint{1, 2, 3}, 1)
if kv != nil {
t.Fatal()
}
kv = SearchSameValue([]uint{1, 2, 3}, uint(1))
if kv.Index() != 0 {
t.Fatal()
}
}
func TestSearchKey(t *testing.T) {
kv := SearchKey([]uint{1, 2, 3}, 2)
if kv == nil {
t.Fatal()
}
if kv.Index() != 2 {
t.Fatal()
}
kv = SearchKey([]uint{1, 2, 3}, 5)
if kv != nil {
t.Fatal()
}
kv = SearchSameKey([]uint{1, 2, 3}, 100)
if kv != nil {
t.Fatal()
}
kv = SearchSameKey([]uint{1, 2, 3}, uint(0))
if kv != nil {
t.Fatal()
}
kv = SearchSameKey([]uint{1, 2, 3}, 1)
if kv == nil {
t.Fatal()
}
}
func TestSearch(t *testing.T) {
kv := Search([]uint{1, 2, 3}, func(k *KeyValue) bool {
return k.Value.String() == "2"
})
if kv == nil {
t.Fatal()
}
if kv.Index() != 1 {
t.Fatal()
}
if kv.Value.String() != "2" {
t.Fatal()
}
}