OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // Dart test for sort routines. | |
6 library sort_test; | |
7 | |
8 import "package:expect/expect.dart"; | |
9 import 'sort_helper.dart'; | |
10 | |
11 main() { | |
12 var compare = (a, b) => a.compareTo(b); | |
13 var sort = (list) => list.sort(compare); | |
14 new SortHelper(sort, compare).run(); | |
15 | |
16 compare = (a, b) => -a.compareTo(b); | |
17 new SortHelper(sort, compare).run(); | |
18 | |
19 compare = (a, b) => a.compareTo(b); | |
20 | |
21 // Pivot-candidate indices: 7, 15, 22, 29, 37 | |
22 // Test Dutch flag partitioning (candidates 2 and 4 are the same). | |
23 var list = [ | |
24 0, | |
25 0, | |
26 0, | |
27 0, | |
28 0, | |
29 0, | |
30 0, | |
31 0 /**/, | |
32 0, | |
33 0, | |
34 0, | |
35 0, | |
36 0, | |
37 0, | |
38 0, | |
39 1 /**/, | |
40 1, | |
41 1, | |
42 1, | |
43 1, | |
44 1, | |
45 1, | |
46 1 /**/, | |
47 1, | |
48 1, | |
49 1, | |
50 1, | |
51 1, | |
52 1, | |
53 1 /**/, | |
54 2, | |
55 2, | |
56 2, | |
57 2, | |
58 2, | |
59 2, | |
60 2, | |
61 2 /**/, | |
62 2, | |
63 2, | |
64 2, | |
65 2, | |
66 2, | |
67 2, | |
68 2 | |
69 ]; | |
70 list.sort(compare); | |
71 Expect.listEquals(list, [ | |
72 0, | |
73 0, | |
74 0, | |
75 0, | |
76 0, | |
77 0, | |
78 0, | |
79 0, | |
80 0, | |
81 0, | |
82 0, | |
83 0, | |
84 0, | |
85 0, | |
86 0, | |
87 1, | |
88 1, | |
89 1, | |
90 1, | |
91 1, | |
92 1, | |
93 1, | |
94 1, | |
95 1, | |
96 1, | |
97 1, | |
98 1, | |
99 1, | |
100 1, | |
101 1, | |
102 2, | |
103 2, | |
104 2, | |
105 2, | |
106 2, | |
107 2, | |
108 2, | |
109 2, | |
110 2, | |
111 2, | |
112 2, | |
113 2, | |
114 2, | |
115 2, | |
116 2 | |
117 ]); | |
118 | |
119 list = [ | |
120 0, | |
121 0, | |
122 0, | |
123 0, | |
124 0, | |
125 0, | |
126 0, | |
127 1 /**/, | |
128 0, | |
129 0, | |
130 0, | |
131 0, | |
132 0, | |
133 0, | |
134 0, | |
135 0 /**/, | |
136 1, | |
137 1, | |
138 1, | |
139 1, | |
140 1, | |
141 1, | |
142 0 /**/, | |
143 1, | |
144 1, | |
145 1, | |
146 1, | |
147 1, | |
148 1, | |
149 0 /**/, | |
150 2 /**/, | |
151 2, | |
152 2, | |
153 2, | |
154 2, | |
155 2, | |
156 2, | |
157 2 /**/, | |
158 2, | |
159 2, | |
160 2, | |
161 2, | |
162 2, | |
163 2, | |
164 2 | |
165 ]; | |
166 list.sort(compare); | |
167 Expect.listEquals(list, [ | |
168 0, | |
169 0, | |
170 0, | |
171 0, | |
172 0, | |
173 0, | |
174 0, | |
175 0, | |
176 0, | |
177 0, | |
178 0, | |
179 0, | |
180 0, | |
181 0, | |
182 0, | |
183 0, | |
184 0, | |
185 1, | |
186 1, | |
187 1, | |
188 1, | |
189 1, | |
190 1, | |
191 1, | |
192 1, | |
193 1, | |
194 1, | |
195 1, | |
196 1, | |
197 1, | |
198 2, | |
199 2, | |
200 2, | |
201 2, | |
202 2, | |
203 2, | |
204 2, | |
205 2, | |
206 2, | |
207 2, | |
208 2, | |
209 2, | |
210 2, | |
211 2, | |
212 2 | |
213 ]); | |
214 | |
215 // Pivots: 1 and 8. | |
216 // The second partition will be big (more than 2/3 of the list), and an | |
217 // optimization kicks in that removes the pivots from the partition. | |
218 list = [ | |
219 0, | |
220 9, | |
221 0, | |
222 9, | |
223 3, | |
224 9, | |
225 0, | |
226 1 /**/, | |
227 1, | |
228 0, | |
229 1, | |
230 9, | |
231 8, | |
232 2, | |
233 1, | |
234 1 /**/, | |
235 4, | |
236 5, | |
237 2, | |
238 5, | |
239 0, | |
240 1, | |
241 8 /**/, | |
242 8, | |
243 8, | |
244 5, | |
245 2, | |
246 2, | |
247 9, | |
248 8 /**/, | |
249 8, | |
250 4, | |
251 4, | |
252 1, | |
253 5, | |
254 3, | |
255 2, | |
256 8 /**/, | |
257 5, | |
258 1, | |
259 2, | |
260 8, | |
261 5, | |
262 6, | |
263 8 | |
264 ]; | |
265 list.sort(compare); | |
266 Expect.listEquals(list, [ | |
267 0, | |
268 0, | |
269 0, | |
270 0, | |
271 0, | |
272 1, | |
273 1, | |
274 1, | |
275 1, | |
276 1, | |
277 1, | |
278 1, | |
279 1, | |
280 2, | |
281 2, | |
282 2, | |
283 2, | |
284 2, | |
285 2, | |
286 3, | |
287 3, | |
288 4, | |
289 4, | |
290 4, | |
291 5, | |
292 5, | |
293 5, | |
294 5, | |
295 5, | |
296 5, | |
297 6, | |
298 8, | |
299 8, | |
300 8, | |
301 8, | |
302 8, | |
303 8, | |
304 8, | |
305 8, | |
306 8, | |
307 9, | |
308 9, | |
309 9, | |
310 9, | |
311 9 | |
312 ]); | |
313 } | |
OLD | NEW |