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
|
package dbstore
import (
"fmt"
"reflect"
"testing"
)
func TestByRankLen(t *testing.T) {
tests := []struct {
val []CisaSearchRow
exp int
} {{
val: []CisaSearchRow {},
exp: 0,
}, {
val: []CisaSearchRow { {}, {}, {}, {} },
exp: 4,
}}
for _, test := range(tests) {
t.Run(fmt.Sprintf("%d", test.exp), func(t *testing.T) {
got := byRank(test.val).Len()
if got != test.exp {
t.Errorf("got %d, exp %d", got, test.exp)
}
})
}
}
func TestByRankLess(t *testing.T) {
tests := []struct {
key string
val []CisaSearchRow
exp bool
} {{
key: "lt",
val: []CisaSearchRow { { Rank: 0 }, { Rank: 1 } },
exp: true,
}, {
key: "eq",
val: []CisaSearchRow { { Rank: 1 }, { Rank: 1 } },
exp: false,
}, {
key: "gt",
val: []CisaSearchRow { { Rank: 1 }, { Rank: 0 } },
exp: false,
}}
for _, test := range(tests) {
t.Run(test.key, func(t *testing.T) {
got := byRank(test.val).Less(0, 1)
if got != test.exp {
t.Errorf("got %v, exp %v", got, test.exp)
}
})
}
}
func TestByRankSwap(t *testing.T) {
tests := []struct {
key string
val []CisaSearchRow
exp []CisaSearchRow
} {{
key: "yup",
val: []CisaSearchRow { { Rank: 0 }, { Rank: 1 } },
exp: []CisaSearchRow { { Rank: 1 }, { Rank: 0 } },
}}
for _, test := range(tests) {
t.Run(test.key, func(t *testing.T) {
byRank(test.val).Swap(0, 1)
if !reflect.DeepEqual(test.val, test.exp) {
t.Errorf("got %#v, exp %#v", test.val, test.exp)
}
})
}
}
|