| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Tests priority queue implementations utilities. | 5 /// Tests priority queue implementations utilities. |
| 6 | 6 |
| 7 import "dart:collection"; | 7 import "dart:collection"; |
| 8 import "package:collection/priority_queue.dart"; | 8 import "package:collection/priority_queue.dart"; |
| 9 import "package:unittest/unittest.dart"; | 9 import "package:unittest/unittest.dart"; |
| 10 | 10 |
| 11 void main() { | 11 void main() { |
| 12 testInt(() => new HeapPriorityQueue<int>()); | 12 testInt(() => new HeapPriorityQueue<int>()); |
| 13 testCustom((comparator) => new HeapPriorityQueue<C>(comparator)); | 13 testCustom((comparator) => new HeapPriorityQueue<C>(comparator)); |
| 14 } | 14 } |
| 15 | 15 |
| 16 void testInt(PriorityQueue<int> create()) { | 16 void testInt(PriorityQueue<int> create()) { |
| 17 for (int count in [1, 5, 127, 128, 400]) { | 17 for (int count in [1, 5, 127, 128]) { |
| 18 testQueue("int:$count", | 18 testQueue("int:$count", |
| 19 create, | 19 create, |
| 20 new List<int>.generate(count, (x) => x), | 20 new List<int>.generate(count, (x) => x), |
| 21 count); | 21 count); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 void testCustom(PriorityQueue<C> create(comparator)) { | 25 void testCustom(PriorityQueue<C> create(comparator)) { |
| 26 for (int count in [1, 5, 127, 128, 400]) { | 26 for (int count in [1, 5, 127, 128]) { |
| 27 testQueue("Custom:$count/null", | 27 testQueue("Custom:$count/null", |
| 28 () => create(null), | 28 () => create(null), |
| 29 new List<C>.generate(count, (x) => new C(x)), | 29 new List<C>.generate(count, (x) => new C(x)), |
| 30 new C(count)); | 30 new C(count)); |
| 31 testQueue("Custom:$count/compare", | 31 testQueue("Custom:$count/compare", |
| 32 () => create(compare), | 32 () => create(compare), |
| 33 new List<C>.generate(count, (x) => new C(x)), | 33 new List<C>.generate(count, (x) => new C(x)), |
| 34 new C(count)); | 34 new C(count)); |
| 35 testQueue("Custom:$count/compareNeg", | 35 testQueue("Custom:$count/compareNeg", |
| 36 () => create(compareNeg), | 36 () => create(compareNeg), |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 int compareNeg(C c1, C c2) => c2.value - c1.value; | 158 int compareNeg(C c1, C c2) => c2.value - c1.value; |
| 159 | 159 |
| 160 class C implements Comparable { | 160 class C implements Comparable { |
| 161 final int value; | 161 final int value; |
| 162 const C(this.value); | 162 const C(this.value); |
| 163 int get hashCode => value; | 163 int get hashCode => value; |
| 164 bool operator==(Object other) => other is C && value == other.value; | 164 bool operator==(Object other) => other is C && value == other.value; |
| 165 int compareTo(C other) => value - other.value; | 165 int compareTo(C other) => value - other.value; |
| 166 String toString() => "C($value)"; | 166 String toString() => "C($value)"; |
| 167 } | 167 } |
| OLD | NEW |