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

Unified Diff: tests/lib/async/stream_from_iterable_test.dart

Issue 11794044: Add Stream.fromIterable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added the test file too. Created 7 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
« sdk/lib/core/iterable.dart ('K') | « sdk/lib/core/iterable.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/stream_from_iterable_test.dart
diff --git a/tests/lib/async/stream_from_iterable_test.dart b/tests/lib/async/stream_from_iterable_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..91923f6ca80a377f560e4d9110fecc702f61991f
--- /dev/null
+++ b/tests/lib/async/stream_from_iterable_test.dart
@@ -0,0 +1,66 @@
+// Copyright (c) 2013, 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.
+
+// Test merging streams.
+library dart.test.stream_from_iterable;
+
+import "dart:async";
+import '../../../pkg/unittest/lib/unittest.dart';
+import 'event_helper.dart';
+
+class IterableTest<T> {
+ static int counter = 0;
+ Iterable<T> iterable;
+ IterableTest(this.iterable);
+ void run() {
+ print("TEST! $counter");
floitsch 2013/01/08 13:02:54 remove.
Lasse Reichstein Nielsen 2013/01/09 11:27:36 Done.
+ test("stream from iterable ${counter++}", () {
+ Events expected = new Events.fromIterable(iterable);
+ Stream<T> stream = new Stream<T>.fromIterable(iterable);
+ Events actual = new Events.capture(stream);
+ actual.onDone(expectAsync0(() {
+ Expect.listEquals(expected.events, actual.events);
+ }));
+ });
+ }
+}
+
+main() {
+ new IterableTest([]).run();
+ new IterableTest([1]).run();
+ new IterableTest([1, "two", true, null]).run();
+ new IterableTest<int>([1, 2, 3, 4]).run();
+ new IterableTest<String>(["one", "two", "three", "four"]).run();
+ new IterableTest<int>(new Iterable<int>.generate(1000, (i) => i)).run();
+ new IterableTest<String>(new Iterable<int>.generate(1000, (i) => i)
+ .mappedBy((i) => "$i")).run();
+
+ Iterable<int> iter = new Iterable.generate(25, (i) => i * 2);
+ new Stream.fromIterable(iter).toList().then(expectAsync1((actual) {
+ List expected = iter.toList();
floitsch 2013/01/08 13:02:54 Also expect that the list-size is 25.
Lasse Reichstein Nielsen 2013/01/09 11:27:36 Done.
+ Expect.listEquals(expected, actual);
+ }));
+
+ new Stream.fromIterable(iter)
+ .mappedBy((i) => i * 3)
+ .toList()
+ .then(expectAsync1((actual) {
+ List expected = iter.mappedBy((i) => i * 3).toList();
+ Expect.listEquals(expected, actual);
+ }));
+
+ { // Test pause.
+ Stream stream = new Stream.fromIterable(iter);
+ Events actual = new Events();
+ Subscription subscription = stream.listen((int value) {
+ // Do a 10 ms pause during the playback of the iterable.
floitsch 2013/01/08 13:02:54 I think it would be relatively easy to create anot
Lasse Reichstein Nielsen 2013/01/09 11:27:36 I've made slow_consumer3_test.
+ if (value == 25) { subscription.pause(new Future.delayed(10, () {})); }
+ actual.add(value);
+ }, onDone: expectAsync0(() {
+ actual.close();
+ Events expected = new Events.fromIterable(iter);
+ Expect.listEquals(expected.events, actual.events);
+ }));
+ }
+}
« sdk/lib/core/iterable.dart ('K') | « sdk/lib/core/iterable.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698