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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« sdk/lib/core/iterable.dart ('K') | « sdk/lib/core/iterable.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test merging streams.
6 library dart.test.stream_from_iterable;
7
8 import "dart:async";
9 import '../../../pkg/unittest/lib/unittest.dart';
10 import 'event_helper.dart';
11
12 class IterableTest<T> {
13 static int counter = 0;
14 Iterable<T> iterable;
15 IterableTest(this.iterable);
16 void run() {
17 print("TEST! $counter");
floitsch 2013/01/08 13:02:54 remove.
Lasse Reichstein Nielsen 2013/01/09 11:27:36 Done.
18 test("stream from iterable ${counter++}", () {
19 Events expected = new Events.fromIterable(iterable);
20 Stream<T> stream = new Stream<T>.fromIterable(iterable);
21 Events actual = new Events.capture(stream);
22 actual.onDone(expectAsync0(() {
23 Expect.listEquals(expected.events, actual.events);
24 }));
25 });
26 }
27 }
28
29 main() {
30 new IterableTest([]).run();
31 new IterableTest([1]).run();
32 new IterableTest([1, "two", true, null]).run();
33 new IterableTest<int>([1, 2, 3, 4]).run();
34 new IterableTest<String>(["one", "two", "three", "four"]).run();
35 new IterableTest<int>(new Iterable<int>.generate(1000, (i) => i)).run();
36 new IterableTest<String>(new Iterable<int>.generate(1000, (i) => i)
37 .mappedBy((i) => "$i")).run();
38
39 Iterable<int> iter = new Iterable.generate(25, (i) => i * 2);
40 new Stream.fromIterable(iter).toList().then(expectAsync1((actual) {
41 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.
42 Expect.listEquals(expected, actual);
43 }));
44
45 new Stream.fromIterable(iter)
46 .mappedBy((i) => i * 3)
47 .toList()
48 .then(expectAsync1((actual) {
49 List expected = iter.mappedBy((i) => i * 3).toList();
50 Expect.listEquals(expected, actual);
51 }));
52
53 { // Test pause.
54 Stream stream = new Stream.fromIterable(iter);
55 Events actual = new Events();
56 Subscription subscription = stream.listen((int value) {
57 // 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.
58 if (value == 25) { subscription.pause(new Future.delayed(10, () {})); }
59 actual.add(value);
60 }, onDone: expectAsync0(() {
61 actual.close();
62 Events expected = new Events.fromIterable(iter);
63 Expect.listEquals(expected.events, actual.events);
64 }));
65 }
66 }
OLDNEW
« 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