forked from chen3feng/stl4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_test.go
57 lines (47 loc) · 1.19 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
package stl4go
import (
"testing"
)
func Test_IsSorted(t *testing.T) {
expectTrue(t, IsSorted([]int{}))
expectTrue(t, IsSorted([]int{1, 2, 3, 4}))
expectTrue(t, IsSorted([]int{1, 2, 2, 3, 4}))
expectFalse(t, IsSorted([]int{1, 2, 2, 3, 2}))
}
func Test_IsDescSorted(t *testing.T) {
expectTrue(t, IsDescSorted([]int{}))
expectFalse(t, IsDescSorted([]int{1, 2, 3, 4}))
expectFalse(t, IsDescSorted([]int{1, 2, 2, 3, 4}))
expectTrue(t, IsDescSorted([]int{5, 4, 3, 3, 2}))
}
func Test_Sort(t *testing.T) {
a := []int{5, 4, 3, 2, 1}
Sort(a)
expectTrue(t, IsSorted(a))
}
func Test_DescSort(t *testing.T) {
a := []int{1, 2, 3, 4}
DescSort(a)
expectTrue(t, IsDescSorted(a))
}
func Test_StableSort(t *testing.T) {
a := []int{5, 4, 3, 2, 1}
StableSort(a)
expectTrue(t, IsSorted(a))
}
func Test_DescStableSort(t *testing.T) {
a := []int{1, 2, 3, 4, 5}
DescStableSort(a)
expectTrue(t, IsDescSorted(a))
}
func greater(x, y int) bool { return x > y }
func Test_SortFunc(t *testing.T) {
a := []int{1, 2, 3, 4, 5}
SortFunc(a, greater)
expectTrue(t, IsDescSorted(a))
}
func Test_StableSortFunc(t *testing.T) {
a := []int{1, 2, 3, 4, 5}
StableSortFunc(a, greater)
expectTrue(t, IsDescSorted(a))
}