-
Notifications
You must be signed in to change notification settings - Fork 1
/
sort_test.go
147 lines (126 loc) · 2.84 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package radixsort_test
import (
"reflect"
"sort"
"testing"
"testing/quick"
"github.com/loov/radixsort"
)
func TestUint32_Quick(t *testing.T) {
if err := quick.Check(CheckUint32, nil); err != nil {
t.Error(err)
}
}
func TestUint64_Quick(t *testing.T) {
if err := quick.Check(CheckUint64, nil); err != nil {
t.Error(err)
}
}
func TestUint_Quick(t *testing.T) {
if err := quick.Check(CheckUint, nil); err != nil {
t.Error(err)
}
}
func TestUint32(t *testing.T) {
tests := [][]uint32{
{},
{0},
{0xFF},
{0xFFFFFFFF},
{0, 1},
{1, 0},
{0, 0xFF},
{0xFF, 0},
{0, 0xFFFFFFFF},
{0xFFFFFFFF, 0},
{74, 59, 238, 784, 9845, 959, 905, 0, 0, 42, 7586, 5467984, 7586},
}
for _, test := range tests {
if !CheckUint32(test) {
t.Errorf("failed on input %v", test)
}
}
}
func TestUint64(t *testing.T) {
tests := [][]uint64{
{},
{0},
{0xFF},
{0xFFFFFFFFFFFFFFFF},
{0, 1},
{1, 0},
{0, 0xFF},
{0xFF, 0},
{0, 0xFFFFFFFFFFFFFFFF},
{0xFFFFFFFFFFFFFFFF, 0},
{0xFFFFFFFFFFFFFFF0, 0xFFFFFFFFFFFFFFFF},
{0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFF0},
{74, 59, 238, 784, 9845, 959, 905, 0, 0, 42, 7586, 5467984, 7586},
}
for _, test := range tests {
if !CheckUint64(test) {
t.Errorf("failed on input %v", test)
}
}
}
func TestUint(t *testing.T) {
tests := [][]uint{
{},
{0},
{0xFF},
{0xFFFFFFFF},
{0, 1},
{1, 0},
{0, 0xFF},
{0xFF, 0},
{0, 0xFFFFFFFF},
{0xFFFFFFFF, 0},
{74, 59, 238, 784, 9845, 959, 905, 0, 0, 42, 7586, 5467984, 7586},
}
for _, test := range tests {
if !CheckUint(test) {
t.Errorf("failed on input %v", test)
}
}
}
func CheckUint32(data []uint32) bool {
expected := make([]uint32, len(data))
copy(expected, data)
sort.Slice(expected, func(i, k int) bool {
return expected[i] < expected[k]
})
sorting := make([]uint32, len(data))
copy(sorting, data)
buffer := make([]uint32, len(data))
radixsort.Uint32(sorting, buffer)
return reflect.DeepEqual(expected, sorting)
}
func CheckUint64(data []uint64) bool {
expected := make([]uint64, len(data))
copy(expected, data)
sort.Slice(expected, func(i, k int) bool {
return expected[i] < expected[k]
})
sorting := make([]uint64, len(data))
copy(sorting, data)
buffer := make([]uint64, len(data))
radixsort.Uint64(sorting, buffer)
return reflect.DeepEqual(expected, sorting)
}
func CheckUint(data []uint) bool {
expected := make([]uint, len(data))
copy(expected, data)
sort.Slice(expected, func(i, k int) bool {
return expected[i] < expected[k]
})
sorting := make([]uint, len(data))
copy(sorting, data)
buffer := make([]uint, len(data))
radixsort.Uint(sorting, buffer)
return reflect.DeepEqual(expected, sorting)
}
func TestLargerBuffer(t *testing.T) {
radixsort.Uint([]uint{1, 2, 3}, make([]uint, 5))
radixsort.Uint32([]uint32{1, 2, 3}, make([]uint32, 5))
radixsort.Uint64([]uint64{1, 2, 3}, make([]uint64, 5))
}