forked from Laisky/go-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_test.go
64 lines (55 loc) · 1.23 KB
/
sort_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
package utils_test
import (
"testing"
utils "github.com/Laisky/go-utils"
)
type Item struct {
k string
v int
}
func (i *Item) GetValue() int {
return i.v
}
func (i *Item) GetKey() interface{} {
return i.k
}
func TestSortSmallest(t *testing.T) {
items := utils.PairList{
&Item{k: "1", v: 1},
&Item{k: "99", v: 99},
&Item{k: "40992", v: 40992},
&Item{k: "22", v: 22},
&Item{k: "15", v: 15},
&Item{k: "932", v: 932},
}
utils.SortSmallest(items)
if items[0].GetValue() != 1 {
t.Errorf("except 1, got %v", items[0].GetValue())
}
if items[1].GetValue() != 15 {
t.Errorf("except 15, got %v", items[0].GetValue())
}
if items[2].GetValue() != 22 {
t.Errorf("except 22, got %v", items[0].GetValue())
}
}
func TestSortBiggest(t *testing.T) {
items := utils.PairList{
&Item{k: "1", v: 1},
&Item{k: "99", v: 99},
&Item{k: "40992", v: 40992},
&Item{k: "22", v: 22},
&Item{k: "15", v: 15},
&Item{k: "932", v: 932},
}
utils.SortBiggest(items)
if items[0].GetValue() != 40992 {
t.Errorf("except 40992, got %v", items[0].GetValue())
}
if items[1].GetValue() != 932 {
t.Errorf("except 932, got %v", items[0].GetValue())
}
if items[2].GetValue() != 99 {
t.Errorf("except 99, got %v", items[0].GetValue())
}
}