OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017, 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 import 'package:kernel/heap.dart'; | |
6 import 'package:test/test.dart'; | |
7 | |
8 main() { | |
9 test('sort', () { | |
10 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.
| |
11 var heap = new _intHeap(); | |
12 values.forEach(heap.add); | |
13 values.sort(); | |
14 var result = <int>[]; | |
15 while (heap.isNotEmpty) { | |
16 expect(heap.isEmpty, isFalse); | |
17 result.add(heap.remove()); | |
18 } | |
19 expect(heap.isEmpty, isTrue); | |
20 expect(result, values); | |
21 }); | |
22 } | |
23 | |
24 class _intHeap extends Heap<int> { | |
25 bool sortsBefore(int a, int b) => a < b; | |
26 } | |
OLD | NEW |