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

Unified Diff: tests/corelib/splay_tree_test.dart

Issue 1127043002: Fix SplayTreeMap.from ignoring the compare and isValidKey arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 80a1742640783f9040cc528e72bc07dd117ed490..c6de49736b6fbb9b14bc581de80f801ad4a8f24c 100644
--- a/tests/corelib/splay_tree_test.dart
+++ b/tests/corelib/splay_tree_test.dart
@@ -53,6 +53,7 @@ main() {
testSetFrom();
regressRemoveWhere();
regressRemoveWhere2();
+ regressFromCompare();
}
void regressRemoveWhere() {
@@ -93,3 +94,45 @@ void testSetFrom() {
set2 = new SplayTreeSet<int>.from(set1.where((x) => x is int));
Expect.equals(3, set2.length);
}
+
+
+
+void regressFromCompare() {
+ // Regression test for http://dartbug.com/23387.
+ // The compare and isValidKey arguments to SplayTreeMap.from were ignored.
+
+ int compare(a, b) {
+ if (a is IncomparableKey && b is IncomparableKey) {
+ return b.id - a.id;
+ }
+ throw "isValidKey failure";
+ }
+ bool isValidKey(o) => o is IncomparableKey;
+ IncomparableKey key(int n) => new IncomparableKey(n);
+
+ var entries = {key(0): 0, key(1): 1, key(2): 2, key(0): 0};
+ Expect.equals(4, entries.length);
+ var map = new SplayTreeMap<IncomparableKey, int>.from(
+ entries, compare, isValidKey);
+ Expect.equals(3, map.length);
+ for (int i = 0; i < 3; i++) {
+ Expect.isTrue(map.containsKey(key(i)));
+ Expect.equals(i, map[key(i)]);
+ }
+ Expect.isFalse(map.containsKey(key(5)));
+ Expect.isFalse(map.containsKey(1));
+ Expect.isFalse(map.containsKey("string"));
+ Expect.equals(null, map[key(5)]);
+ Expect.equals(null, map[1]);
+ Expect.equals(null, map["string"]);
+ Expect.throws(() { map[1] = 42; });
+ Expect.throws(() { map["string"] = 42; });
+ map[key(5)] = 42;
+ Expect.equals(4, map.length);
+ Expect.equals(42, map[key(5)]);
+}
+
+class IncomparableKey {
+ final int id;
+ IncomparableKey(this.id);
+}
« 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