Index: pkg/kernel/test/heap_test.dart |
diff --git a/pkg/kernel/test/heap_test.dart b/pkg/kernel/test/heap_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..56d4b47ea61be3d3d7c3cf43eea3455832dd1454 |
--- /dev/null |
+++ b/pkg/kernel/test/heap_test.dart |
@@ -0,0 +1,26 @@ |
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+import 'package:kernel/heap.dart'; |
+import 'package:test/test.dart'; |
+ |
+main() { |
+ test('sort', () { |
+ var values = <int>[3, 1, 4, 1, 5, 9, 2, 6]; |
ahe
2017/05/01 16:50:34
Would it make sense to test a list that is sorted,
Paul Berry
2017/05/01 18:12:14
Yes, good idea. Done.
|
+ var heap = new _intHeap(); |
+ values.forEach(heap.add); |
+ values.sort(); |
+ var result = <int>[]; |
+ while (heap.isNotEmpty) { |
+ expect(heap.isEmpty, isFalse); |
+ result.add(heap.remove()); |
+ } |
+ expect(heap.isEmpty, isTrue); |
+ expect(result, values); |
+ }); |
+} |
+ |
+class _intHeap extends Heap<int> { |
+ bool sortsBefore(int a, int b) => a < b; |
+} |