| 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("SortTest.dart"); | |
| 7 #import("dart:coreimpl"); | |
| 8 #source("SortHelper.dart"); | |
| 9 | |
| 10 main() { | |
| 11 var compare = (a, b) => a.compareTo(b); | |
| 12 var sort = (list) => DualPivotQuicksort.sort(list, compare); | |
| 13 new SortHelper(sort, compare).run(); | |
| 14 | |
| 15 compare = (a, b) => -a.compareTo(b); | |
| 16 new SortHelper(sort, compare).run(); | |
| 17 | |
| 18 compare = (a, b) => a.compareTo(b); | |
| 19 | |
| 20 // Pivot-canditate indices: 7, 15, 22, 29, 37 | |
| 21 // Test dutch flag partitioning (canditates 2 and 4 are the same). | |
| 22 var list = [0, 0, 0, 0, 0, 0, 0, 0/**/, 0, 0, 0, 0, 0, 0, 0, | |
| 23 1/**/, 1, 1, 1, 1, 1, 1, 1/**/, 1, 1, 1, 1, 1, 1, 1/**/, | |
| 24 2, 2, 2, 2, 2, 2, 2, 2/**/, 2, 2, 2, 2, 2, 2, 2]; | |
| 25 list.sort(compare); | |
| 26 Expect.listEquals(list, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 27 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
| 28 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]); | |
| 29 | |
| 30 list = [0, 0, 0, 0, 0, 0, 0, 1/**/, 0, 0, 0, 0, 0, 0, 0, | |
| 31 0/**/, 1, 1, 1, 1, 1, 1, 0/**/, 1, 1, 1, 1, 1, 1, 0/**/, | |
| 32 2/**/, 2, 2, 2, 2, 2, 2, 2/**/, 2, 2, 2, 2, 2, 2, 2]; | |
| 33 list.sort(compare); | |
| 34 Expect.listEquals(list, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 35 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
| 36 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]); | |
| 37 | |
| 38 // Pivots: 1 and 8. | |
| 39 // The second partition will be big (more than 2/3 of the list), and an | |
| 40 // optimization kicks in that removes the pivots from the partition. | |
| 41 list = [0, 9, 0, 9, 3, 9, 0, 1/**/, 1, 0, 1, 9, 8, 2, 1, | |
| 42 1/**/, 4, 5, 2, 5, 0, 1, 8/**/, 8, 8, 5, 2, 2, 9, 8/**/, | |
| 43 8, 4, 4, 1, 5, 3, 2, 8/**/, 5, 1, 2, 8, 5, 6, 8]; | |
| 44 list.sort(compare); | |
| 45 Expect.listEquals(list, [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | |
| 46 2, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, | |
| 47 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]); | |
| 48 } | |
| OLD | NEW |