| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart test for Splaytrees. | 5 // Dart test for Splaytrees. |
| 6 library splay_tree_test; | 6 library splay_tree_test; |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 Expect.equals(4, tree.lastKeyBefore(5)); | 44 Expect.equals(4, tree.lastKeyBefore(5)); |
| 45 Expect.equals(7, tree.firstKeyAfter(5)); | 45 Expect.equals(7, tree.firstKeyAfter(5)); |
| 46 | 46 |
| 47 Expect.equals(5, tree.lastKeyBefore(7)); | 47 Expect.equals(5, tree.lastKeyBefore(7)); |
| 48 Expect.equals(null, tree.firstKeyAfter(7)); | 48 Expect.equals(null, tree.firstKeyAfter(7)); |
| 49 | 49 |
| 50 Expect.equals(5, tree.lastKeyBefore(6)); | 50 Expect.equals(5, tree.lastKeyBefore(6)); |
| 51 Expect.equals(7, tree.firstKeyAfter(6)); | 51 Expect.equals(7, tree.firstKeyAfter(6)); |
| 52 | 52 |
| 53 regressRemoveWhere(); | 53 regressRemoveWhere(); |
| 54 regressRemoveWhere2(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void regressRemoveWhere() { | 57 void regressRemoveWhere() { |
| 57 // Regression test. Fix in https://codereview.chromium.org/148523006/ | 58 // Regression test. Fix in https://codereview.chromium.org/148523006/ |
| 58 var t = new SplayTreeSet(); | 59 var t = new SplayTreeSet(); |
| 59 t.addAll([1,3,5,7,2,4,6,8,0]); | 60 t.addAll([1,3,5,7,2,4,6,8,0]); |
| 60 var seen = new List<bool>.filled(9, false); | 61 var seen = new List<bool>.filled(9, false); |
| 61 t.removeWhere((x) { | 62 t.removeWhere((x) { |
| 62 // Called only once per element. | 63 // Called only once per element. |
| 63 Expect.isFalse(seen[x], "seen $x"); | 64 Expect.isFalse(seen[x], "seen $x"); |
| 64 seen[x] = true; | 65 seen[x] = true; |
| 65 return x.isOdd; | 66 return x.isOdd; |
| 66 }); | 67 }); |
| 67 } | 68 } |
| 69 |
| 70 void regressRemoveWhere2() { |
| 71 // Regression test for http://dartbug.com/18676 |
| 72 // Removing all elements with removeWhere causes error. |
| 73 |
| 74 var t = new SplayTreeSet(); |
| 75 t.addAll([1,2,3,4,5]); |
| 76 t.removeWhere((_) => true); // Should not throw. |
| 77 Expect.isTrue(t.isEmpty); |
| 78 t.addAll([1,2,3,4,5]); |
| 79 t.retainWhere((_) => false); // Should not throw. |
| 80 Expect.isTrue(t.isEmpty); |
| 81 } |
| OLD | NEW |