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

Unified Diff: tests/corelib/collection_test.dart

Issue 10827293: Reapply 'Add reduce to Collection.' (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add fixes. Created 8 years, 4 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
« runtime/lib/array.dart ('K') | « runtime/lib/growable_array.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/collection_test.dart
diff --git a/tests/corelib/collection_test.dart b/tests/corelib/collection_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..87bb8538de88f34304f7405416ddec6706645296
--- /dev/null
+++ b/tests/corelib/collection_test.dart
@@ -0,0 +1,35 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class CollectionTest {
Ivan Posva 2012/08/13 16:58:45 To me it feels like this file will explode as you
Anders Johnsen 2012/08/14 05:38:27 I agree that we test two dimensions, but we only h
Lasse Reichstein Nielsen 2012/08/14 09:00:07 I think this is fine. I prefer a templated test to
+ CollectionTest(Collection collection) {
+ testReduce(collection);
+ }
+
+ void testReduce(Collection collection) {
+ Expect.equals(28, collection.reduce(0, (prev, element) => prev + element));
+ Expect.equals(
+ 3024, collection.reduce(1, (prev, element) => prev * element));
+ }
+}
+
+
+main() {
+ final TEST_ELEMENTS = const [4, 2, 6, 7, 9];
+ // Const list.
+ new CollectionTest(TEST_ELEMENTS);
+
+ // Fixed size list.
+ var fixedList = new List(TEST_ELEMENTS.length);
+ for (int i = 0; i < TEST_ELEMENTS.length; i++) {
+ fixedList[i] = TEST_ELEMENTS[i];
+ }
+ new CollectionTest(fixedList);
+
+ // Dynamic size list.
+ new CollectionTest(new List.from(TEST_ELEMENTS));
+
+ // Dynamic size set.
+ new CollectionTest(new Set.from(TEST_ELEMENTS));
+}
Lasse Reichstein Nielsen 2012/08/14 09:00:07 BTW, you might want to make a test with zero eleme
« runtime/lib/array.dart ('K') | « runtime/lib/growable_array.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698