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

Unified Diff: tests/corelib/set_test.dart

Issue 838463002: Change List/Set/Map/Queue.from constructrs to accept any iterable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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
Index: tests/corelib/set_test.dart
diff --git a/tests/corelib/set_test.dart b/tests/corelib/set_test.dart
index 8867126361aff28ddd8a3d03943dd055a78fc299..204bf7d5ff4b9b83b71384a6e72008ae3179ad34 100644
--- a/tests/corelib/set_test.dart
+++ b/tests/corelib/set_test.dart
@@ -408,6 +408,43 @@ void testIdentity(Set create()) {
Expect.isTrue(set2.contains(e2));
}
+void testIntSetFrom(setFrom) {
+ List<num> numList = [2, 3, 5, 7, 11, 13];
+
+ Set<int> set1 = setFrom(numList);
+ Expect.listEquals(numList, set1.toList()..sort());
+
+ Set<num> numSet = numList.toSet();
+ Set<int> set2 = setFrom(numSet);
+ Expect.listEquals(numList, set2.toList()..sort());
+
+ Iterable<num> numIter = numList.where((x) => true);
+ Set<int> set3 = setFrom(numIter);
+ Expect.listEquals(numList, set3.toList()..sort());
+
+ Set<int> set4 = setFrom(new Iterable.generate(0));
+ Expect.isTrue(set4.isEmpty);
+}
+
+void testCESetFrom(setFrom) {
+ List<Object> ceList = [new CE(2), new CE(3), new CE(5),
+ new CE(7), new CE(11), new CE(13)];
+
+ Set<CE> set1 = setFrom(ceList);
+ Expect.listEquals(ceList, set1.toList()..sort());
+
+ Set<ce> ceSet = ceList.toSet();
+ Set<CE> set2 = setFrom(ceSet);
+ Expect.listEquals(ceList, set2.toList()..sort());
+
+ Iterable<ce> ceIter = ceList.where((x) => true);
+ Set<CE> set3 = setFrom(ceIter);
+ Expect.listEquals(ceList, set3.toList()..sort());
+
+ Set<CE> set4 = setFrom(new Iterable.generate(0));
+ Expect.isTrue(set4.isEmpty);
+}
+
main() {
testMain(() => new HashSet());
testMain(() => new LinkedHashSet());
@@ -457,4 +494,18 @@ main() {
isValidKey: validKey));
testDifferenceIntersection(([equals, hashCode, validKey, comparator]) =>
new SplayTreeSet(comparator, validKey));
+
+ testIntSetFrom((x) => new Set<int>.from(x));
+ testIntSetFrom((x) => new HashSet<int>.from(x));
+ testIntSetFrom((x) => new LinkedHashSet<int>.from(x));
+ testIntSetFrom((x) => new SplayTreeSet<int>.from(x));
+
+ testCESetFrom((x) => new Set<CE>.from(x));
+ testCESetFrom((x) => new HashSet<CE>.from(x));
+ testCESetFrom((x) => new LinkedHashSet<CE>.from(x));
+ testCESetFrom((x) => new SplayTreeSet<CE>.from(x));
+
+ testCESetFrom((x) => new SplayTreeSet<CE>.from(x,
+ customCompare(20), validKey));
+ testCESetFrom((x) => new SplayTreeSet<CE>.from(x, identityCompare));
}

Powered by Google App Engine
This is Rietveld 408576698