Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Unified Diff: tests/corelib/splay_tree_test.dart

Issue 148523006: Fix bug in internal SplayTreeIterator constructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added test. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/collection/splay_tree.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/splay_tree_test.dart
diff --git a/tests/corelib/splay_tree_test.dart b/tests/corelib/splay_tree_test.dart
index ae112d4b76be95c68b9e1717573db0ced0137123..ee3083df577fc02a6a90d0514e0950e959e56cc9 100644
--- a/tests/corelib/splay_tree_test.dart
+++ b/tests/corelib/splay_tree_test.dart
@@ -8,51 +8,60 @@ import "package:expect/expect.dart";
import 'dart:collection';
-class SplayTreeMapTest {
+main() {
+ // Simple tests.
+ SplayTreeMap tree = new SplayTreeMap();
+ tree[1] = "first";
+ tree[3] = "third";
+ tree[5] = "fifth";
+ tree[2] = "second";
+ tree[4] = "fourth";
- static testMain() {
- SplayTreeMap tree = new SplayTreeMap();
- tree[1] = "first";
- tree[3] = "third";
- tree[5] = "fifth";
- tree[2] = "second";
- tree[4] = "fourth";
+ var correctSolution = ["first", "second", "third", "fourth", "fifth"];
- var correctSolution = ["first", "second", "third", "fourth", "fifth"];
+ tree.forEach((key, value) {
+ Expect.equals(true, key >= 1);
+ Expect.equals(true, key <= 5);
+ Expect.equals(value, correctSolution[key - 1]);
+ });
- tree.forEach((key, value) {
- Expect.equals(true, key >= 1);
- Expect.equals(true, key <= 5);
- Expect.equals(value, correctSolution[key - 1]);
- });
+ for (var v in ["first", "second", "third", "fourth", "fifth"]) {
+ Expect.isTrue(tree.containsValue(v));
+ };
+ Expect.isFalse(tree.containsValue("sixth"));
- for (var v in ["first", "second", "third", "fourth", "fifth"]) {
- Expect.isTrue(tree.containsValue(v));
- };
- Expect.isFalse(tree.containsValue("sixth"));
+ tree[7] = "seventh";
- tree[7] = "seventh";
+ Expect.equals(1, tree.firstKey());
+ Expect.equals(7, tree.lastKey());
- Expect.equals(1, tree.firstKey());
- Expect.equals(7, tree.lastKey());
+ Expect.equals(2, tree.lastKeyBefore(3));
+ Expect.equals(4, tree.firstKeyAfter(3));
- Expect.equals(2, tree.lastKeyBefore(3));
- Expect.equals(4, tree.firstKeyAfter(3));
+ Expect.equals(null, tree.lastKeyBefore(1));
+ Expect.equals(2, tree.firstKeyAfter(1));
- Expect.equals(null, tree.lastKeyBefore(1));
- Expect.equals(2, tree.firstKeyAfter(1));
+ Expect.equals(4, tree.lastKeyBefore(5));
+ Expect.equals(7, tree.firstKeyAfter(5));
- Expect.equals(4, tree.lastKeyBefore(5));
- Expect.equals(7, tree.firstKeyAfter(5));
+ Expect.equals(5, tree.lastKeyBefore(7));
+ Expect.equals(null, tree.firstKeyAfter(7));
- Expect.equals(5, tree.lastKeyBefore(7));
- Expect.equals(null, tree.firstKeyAfter(7));
+ Expect.equals(5, tree.lastKeyBefore(6));
+ Expect.equals(7, tree.firstKeyAfter(6));
- Expect.equals(5, tree.lastKeyBefore(6));
- Expect.equals(7, tree.firstKeyAfter(6));
- }
+ regressRemoveWhere();
}
-main() {
- SplayTreeMapTest.testMain();
+void regressRemoveWhere() {
+ // Regression test. Fix in https://codereview.chromium.org/148523006/
+ var t = new SplayTreeSet();
+ t.addAll([1,3,5,7,2,4,6,8,0]);
+ var seen = new List<bool>.filled(9, false);
+ t.removeWhere((x) {
+ // Called only once per element.
+ Expect.isFalse(seen[x], "seen $x");
+ seen[x] = true;
+ return x.isOdd;
+ });
}
« no previous file with comments | « sdk/lib/collection/splay_tree.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698