forked from facette/natsort
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnatsort_test.go
179 lines (166 loc) · 3.17 KB
/
natsort_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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package natsort
import (
"reflect"
"sort"
"strings"
"testing"
"github.com/maruel/natural"
)
var testList = []string{
"1000X Radonius Maximus",
"000050X Radonius",
"10X Radonius",
"200X Radonius",
"20X Radonius",
"20X Radonius Prime",
"30X Radonius",
"40X Radonius",
"Allegia 50 Clasteron",
"Allegia 500 Clasteron",
"Allegia 50B Clasteron",
"Allegia 51 Clasteron",
"Allegia 6R Clasteron",
"Alpha 100",
"Alpha 2",
"Alpha 200",
"Alpha 2A",
"Alpha 2A-8000",
"Alpha 2A-900",
"Callisto Morphamax",
"Callisto Morphamax 500",
"Callisto Morphamax 5000",
"Callisto Morphamax 600",
"Callisto Morphamax 6000 SE",
"Callisto Morphamax 6000 SE2",
"Callisto Morphamax 700",
"Callisto Morphamax 7000",
"Xiph Xlater 10000",
"Xiph Xlater 2000",
"Xiph Xlater 300",
"Xiph Xlater 40",
"Xiph Xlater 5",
"Xiph Xlater 50",
"Xiph Xlater 500",
"Xiph Xlater 5000",
"Xiph Xlater 58",
}
func Test_Sort1(t *testing.T) {
testListSortedOK := []string{
"10X Radonius",
"20X Radonius",
"20X Radonius Prime",
"30X Radonius",
"40X Radonius",
"000050X Radonius",
"200X Radonius",
"1000X Radonius Maximus",
"Allegia 6R Clasteron",
"Allegia 50 Clasteron",
"Allegia 50B Clasteron",
"Allegia 51 Clasteron",
"Allegia 500 Clasteron",
"Alpha 2",
"Alpha 2A",
"Alpha 2A-900",
"Alpha 2A-8000",
"Alpha 100",
"Alpha 200",
"Callisto Morphamax",
"Callisto Morphamax 500",
"Callisto Morphamax 600",
"Callisto Morphamax 700",
"Callisto Morphamax 5000",
"Callisto Morphamax 6000 SE",
"Callisto Morphamax 6000 SE2",
"Callisto Morphamax 7000",
"Xiph Xlater 5",
"Xiph Xlater 40",
"Xiph Xlater 50",
"Xiph Xlater 58",
"Xiph Xlater 300",
"Xiph Xlater 500",
"Xiph Xlater 2000",
"Xiph Xlater 5000",
"Xiph Xlater 10000",
}
testListSorted := testList[:]
Sort(testListSorted)
if !reflect.DeepEqual(testListSortedOK, testListSorted) {
t.Fatalf(`ERROR: sorted list different from expected results:
Expected results:
%v
Got:
%v`, strings.Join(testListSortedOK, "\n"), strings.Join(testListSorted, "\n"))
}
}
func Test_Sort2(t *testing.T) {
testList := []string{
"z1.doc",
"z10.doc",
"z100.doc",
"z101.doc",
"z102.doc",
"z11.doc",
"z12.doc",
"z13.doc",
"z14.doc",
"z15.doc",
"z16.doc",
"z17.doc",
"z18.doc",
"z19.doc",
"z2.doc",
"z20.doc",
"z3.doc",
"z4.doc",
"z5.doc",
"z6.doc",
"z7.doc",
"z8.doc",
"z9.doc",
}
testListSortedOK := []string{
"z1.doc",
"z2.doc",
"z3.doc",
"z4.doc",
"z5.doc",
"z6.doc",
"z7.doc",
"z8.doc",
"z9.doc",
"z10.doc",
"z11.doc",
"z12.doc",
"z13.doc",
"z14.doc",
"z15.doc",
"z16.doc",
"z17.doc",
"z18.doc",
"z19.doc",
"z20.doc",
"z100.doc",
"z101.doc",
"z102.doc",
}
testListSorted := testList[:]
Sort(testListSorted)
if !reflect.DeepEqual(testListSortedOK, testListSorted) {
t.Fatalf(`ERROR: sorted list different from expected results:
Expected results:
%v
Got:
%v`, strings.Join(testListSortedOK, "\n"), strings.Join(testListSorted, "\n"))
}
}
func BenchmarkSort1(b *testing.B) {
for n := 0; n < b.N; n++ {
Sort(testList)
}
}
func BenchmarkSortMaruelNatural(b *testing.B) {
for n := 0; n < b.N; n++ {
sort.Sort(natural.StringSlice(testList))
}
}