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

Unified Diff: tests/corelib/set_test.dart

Issue 288103003: Change Set.toSet to always return a set with the same behavior. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Change .clone() to use .toSet(). Update docs. Created 6 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
Index: tests/corelib/set_test.dart
diff --git a/tests/corelib/set_test.dart b/tests/corelib/set_test.dart
index 32ec5206c2430db4b24acc07c88d47e521d54092..4e1b7778c92459ad806b6d01e2015323417ef040 100644
--- a/tests/corelib/set_test.dart
+++ b/tests/corelib/set_test.dart
@@ -11,6 +11,10 @@ import "dart:collection";
void testMain(Set create()) {
testInts(create);
testStrings(create);
+ testInts(() => create().toSet());
+ testStrings(() => create().toSet());
+ testInts(() => create().cloneEmpty());
+ testStrings(() => create().cloneEmpty());
}
void testInts(Set create()) {
@@ -190,6 +194,29 @@ void testInts(Set create()) {
testLength(0, set);
Expect.isTrue(set.add(11));
testLength(1, set);
+
+ // Test Set.toSet and Set.cloneEmpty.
+ set.add(1);
+ set.add(21);
+ testLength(3, set);
+ var set2 = set.toSet();
+ testLength(3, set2);
+ Expect.listEquals(set.toList(), set2.toList());
+ set.add(31);
+ testLength(4, set);
+ testLength(3, set2);
+
+ set2 = set.cloneEmpty();
+ testLength(0, set2);
+ Expect.isTrue(set2.add(11));
+ Expect.isTrue(set2.add(1));
+ Expect.isTrue(set2.add(21));
+ Expect.isTrue(set2.add(31));
+ testLength(4, set2);
+ Expect.listEquals(set.toList(), set2.toList());
+
+ set2 = set.cloneEmpty().toSet(); // Cloning empty set shouldn't fail.
+ testLength(0, set2);
}
void testLength(int length, Set set) {
@@ -359,9 +386,35 @@ int identityCompare(e1, e2) {
return i1 - i2;
}
+void testIdentity(Set create()) {
+ Set set = create();
+ var e1 = new CE(0);
+ var e2 = new CE(0);
+ Expect.equals(e1, e2);
+ Expect.isFalse(identical(e1, e2));
+
+ testLength(0, set);
+ set.add(e1);
+ testLength(1, set);
+ Expect.isTrue(set.contains(e1));
+ Expect.isFalse(set.contains(e2));
+
+ set.add(e2);
+ testLength(2, set);
+ Expect.isTrue(set.contains(e1));
+ Expect.isTrue(set.contains(e2));
+
+ var set2 = set.toSet();
+ testLength(2, set2);
+ Expect.isTrue(set2.contains(e1));
+ Expect.isTrue(set2.contains(e2));
+}
+
main() {
testMain(() => new HashSet());
testMain(() => new LinkedHashSet());
+ testMain(() => new HashSet.identity());
+ testMain(() => new LinkedHashSet.identity());
testMain(() => new HashSet(equals: identical));
testMain(() => new LinkedHashSet(equals: identical));
testMain(() => new HashSet(equals: (a, b) => a == b,
@@ -373,6 +426,12 @@ main() {
isValidKey: (a) => true));
testMain(() => new SplayTreeSet());
+ testIdentity(() => new HashSet.identity());
+ testIdentity(() => new LinkedHashSet.identity());
+ testIdentity(() => new HashSet(equals: identical));
+ testIdentity(() => new LinkedHashSet(equals: identical));
+ testIdentity(() => new SplayTreeSet(identityCompare));
+
testTypeAnnotations(new HashSet<int>());
testTypeAnnotations(new LinkedHashSet<int>());
testTypeAnnotations(new HashSet<int>(equals: identical));
@@ -400,5 +459,4 @@ main() {
isValidKey: validKey));
testDifferenceIntersection(([equals, hashCode, validKey, comparator]) =>
new SplayTreeSet(comparator, validKey));
-
}

Powered by Google App Engine
This is Rietveld 408576698