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

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: Update html5lib pubspec version to 0.12.0-dev 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
« pkg/third_party/html5lib/pubspec.yaml ('K') | « sdk/lib/core/set.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/set_test.dart
diff --git a/tests/corelib/set_test.dart b/tests/corelib/set_test.dart
index 32ec5206c2430db4b24acc07c88d47e521d54092..8867126361aff28ddd8a3d03943dd055a78fc299 100644
--- a/tests/corelib/set_test.dart
+++ b/tests/corelib/set_test.dart
@@ -11,6 +11,8 @@ import "dart:collection";
void testMain(Set create()) {
testInts(create);
testStrings(create);
+ testInts(() => create().toSet());
+ testStrings(() => create().toSet());
}
void testInts(Set create()) {
@@ -190,6 +192,29 @@ void testInts(Set create()) {
testLength(0, set);
Expect.isTrue(set.add(11));
testLength(1, set);
+
+ // Test Set.toSet.
+ 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.toSet()..clear();
+ 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.toSet()..clear()).toSet(); // Cloning empty set shouldn't fail.
+ testLength(0, set2);
}
void testLength(int length, Set set) {
@@ -359,9 +384,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 +424,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 +457,4 @@ main() {
isValidKey: validKey));
testDifferenceIntersection(([equals, hashCode, validKey, comparator]) =>
new SplayTreeSet(comparator, validKey));
-
}
« pkg/third_party/html5lib/pubspec.yaml ('K') | « sdk/lib/core/set.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698