Index: packages/collection/test/priority_queue_test.dart |
diff --git a/packages/collection/test/priority_queue_test.dart b/packages/collection/test/priority_queue_test.dart |
index 264bf94fbdd5f5658c3407cbf9a599385b810f4d..0e493e5a63924e98e9545a3a906fcdb2f784059f 100644 |
--- a/packages/collection/test/priority_queue_test.dart |
+++ b/packages/collection/test/priority_queue_test.dart |
@@ -4,45 +4,46 @@ |
/// Tests priority queue implementations utilities. |
-import "package:collection/priority_queue.dart"; |
import "package:test/test.dart"; |
+import "package:collection/src/priority_queue.dart"; |
+ |
void main() { |
+ testDefault(); |
testInt(() => new HeapPriorityQueue<int>()); |
testCustom((comparator) => new HeapPriorityQueue<C>(comparator)); |
} |
+void testDefault() { |
+ test('new PriorityQueue() returns a HeapPriorityQueue', () { |
+ expect( |
+ new PriorityQueue<int>(), new isInstanceOf<HeapPriorityQueue<int>>()); |
+ }); |
+ testInt(() => new PriorityQueue<int>()); |
+ testCustom((comparator) => new PriorityQueue<C>(comparator)); |
+} |
+ |
void testInt(PriorityQueue<int> create()) { |
for (int count in [1, 5, 127, 128]) { |
- testQueue("int:$count", |
- create, |
- new List<int>.generate(count, (x) => x), |
- count); |
+ testQueue( |
+ "int:$count", create, new List<int>.generate(count, (x) => x), count); |
} |
} |
void testCustom(PriorityQueue<C> create(comparator)) { |
for (int count in [1, 5, 127, 128]) { |
- testQueue("Custom:$count/null", |
- () => create(null), |
- new List<C>.generate(count, (x) => new C(x)), |
- new C(count)); |
- testQueue("Custom:$count/compare", |
- () => create(compare), |
- new List<C>.generate(count, (x) => new C(x)), |
- new C(count)); |
- testQueue("Custom:$count/compareNeg", |
- () => create(compareNeg), |
- new List<C>.generate(count, (x) => new C(count - x)), |
- new C(0)); |
+ testQueue("Custom:$count/null", () => create(null), |
+ new List<C>.generate(count, (x) => new C(x)), new C(count)); |
+ testQueue("Custom:$count/compare", () => create(compare), |
+ new List<C>.generate(count, (x) => new C(x)), new C(count)); |
+ testQueue("Custom:$count/compareNeg", () => create(compareNeg), |
+ new List<C>.generate(count, (x) => new C(count - x)), new C(0)); |
} |
} |
-/** |
- * Test that a queue behaves correctly. |
- * |
- * The elements must be in priority order, from highest to lowest. |
- */ |
+/// Test that a queue behaves correctly. |
+/// |
+/// The elements must be in priority order, from highest to lowest. |
void testQueue(String name, PriorityQueue create(), List elements, notElement) { |
test(name, () => testQueueBody(create, elements, notElement)); |
} |
@@ -51,8 +52,12 @@ void testQueueBody(PriorityQueue create(), List elements, notElement) { |
PriorityQueue q = create(); |
expect(q.isEmpty, isTrue); |
expect(q, hasLength(0)); |
- expect(() { q.first; }, throwsStateError); |
- expect(() { q.removeFirst(); }, throwsStateError); |
+ expect(() { |
+ q.first; |
+ }, throwsStateError); |
+ expect(() { |
+ q.removeFirst(); |
+ }, throwsStateError); |
// Tests removeFirst, first, contains, toList and toSet. |
void testElements() { |
@@ -108,6 +113,7 @@ void testQueueBody(PriorityQueue create(), List elements, notElement) { |
if (mid + 1 < max) addRec(mid + 1, max); |
if (mid > min) addRec(min, mid); |
} |
+ |
addRec(0, elements.length); |
testElements(); |
@@ -150,17 +156,16 @@ void testQueueBody(PriorityQueue create(), List elements, notElement) { |
expect(q.isEmpty, isTrue); |
} |
- |
// Custom class. |
// Class is comparable, comparators match normal and inverse order. |
int compare(C c1, C c2) => c1.value - c2.value; |
int compareNeg(C c1, C c2) => c2.value - c1.value; |
-class C implements Comparable { |
+class C implements Comparable<C> { |
final int value; |
const C(this.value); |
int get hashCode => value; |
- bool operator==(Object other) => other is C && value == other.value; |
+ bool operator ==(Object other) => other is C && value == other.value; |
int compareTo(C other) => value - other.value; |
String toString() => "C($value)"; |
} |