-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_test.go
53 lines (45 loc) · 973 Bytes
/
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
package quick
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestSort(t *testing.T) {
cases := map[string]struct {
input testData
expected testData
}{
"sort three items": {
input: testData{2, 1, 3},
expected: testData{1, 2, 3},
},
"sort descending list": {
input: testData{10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
expected: testData{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
},
"sort random list": {
input: testData{6, 2, 7, 1, 9, 10, 8, 3, 5, 4},
expected: testData{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
},
"sort empty list": {
input: testData{},
expected: testData{},
},
}
for n, tc := range cases {
t.Run(n, func(t *testing.T) {
a := assert.New(t)
Sort(tc.input)
a.Equal(tc.expected, tc.input)
})
}
}
type testData []int
func (d testData) Len() int {
return len(d)
}
func (d testData) Less(i, j int) bool {
return d[i] < d[j]
}
func (d testData) Swap(i, j int) {
d[i], d[j] = d[j], d[i]
}