add a forward constructor in PriorityQueue to HeapPriorityQueue
diff --git a/lib/priority_queue.dart b/lib/priority_queue.dart
index e1a0177..6272445 100644
--- a/lib/priority_queue.dart
+++ b/lib/priority_queue.dart
@@ -13,6 +13,19 @@
*/
abstract class PriorityQueue<E> {
/**
+ * Creates an empty [PriorityQueue].
+ *
+ * The created [PriorityQueue] is a plain [HeapPriorityQueue].
+ *
+ * The [comparison] is a [Comparator] used to compare the priority of
+ * elements. An element that compares as less than another element has
+ * a higher priority.
+ *
+ * If [comparison] is omitted, it defaults to [Comparable.compare].
+ */
+ factory PriorityQueue([int comparison(E e1, E e2)]) = HeapPriorityQueue<E>;
+
+ /**
* Number of elements in the queue.
*/
int get length;
diff --git a/test/priority_queue_test.dart b/test/priority_queue_test.dart
index 264bf94..cda0748 100644
--- a/test/priority_queue_test.dart
+++ b/test/priority_queue_test.dart
@@ -8,10 +8,20 @@
import "package:test/test.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",