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

Side by Side Diff: tests/lib/async/futures_test.dart

Issue 2853203002: Change Future.doWhile to use a loop for non-future results instead of recursion. (Closed)
Patch Set: Address comment. Created 3 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 unified diff | Download patch
« no previous file with comments | « sdk/lib/async/future.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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library futures_test; 5 library futures_test;
6 6
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 import 'dart:async'; 9 import 'dart:async';
10 10
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 count++; 231 count++;
232 if (count == 4) throw 'correct exception'; 232 if (count == 4) throw 'correct exception';
233 return new Future(() => true); 233 return new Future(() => true);
234 }).then((_) { 234 }).then((_) {
235 throw 'incorrect exception'; 235 throw 'incorrect exception';
236 }).catchError((error) { 236 }).catchError((error) {
237 Expect.equals('correct exception', error); 237 Expect.equals('correct exception', error);
238 }); 238 });
239 } 239 }
240 240
241 Future testDoWhileManyFutures() {
242 int n = 100000;
243 var ftrue = new Future.value(false);
244 var ffalse = new Future.value(false);
245 return Future.doWhile(() {
246 return (--n > 0) ? ftrue : ffalse;
247 }).then((_) {
248 // Success
249 }, onError: (e, s) {
250 Expect.fail("$e\n$s");
251 });
252 }
253
254 Future testDoWhileManyValues() {
255 int n = 100000;
256 return Future.doWhile(() {
257 return (--n > 0);
258 }).then((_) {
259 // Success
260 }, onError: (e, s) {
261 Expect.fail("$e\n$s");
262 });
263 }
264
241 main() { 265 main() {
242 List<Future> futures = new List<Future>(); 266 List<Future> futures = new List<Future>();
243 267
244 futures.add(testWaitEmpty()); 268 futures.add(testWaitEmpty());
245 futures.add(testCompleteAfterWait()); 269 futures.add(testCompleteAfterWait());
246 futures.add(testCompleteBeforeWait()); 270 futures.add(testCompleteBeforeWait());
247 futures.add(testWaitWithMultipleValues()); 271 futures.add(testWaitWithMultipleValues());
248 futures.add(testWaitWithSingleError()); 272 futures.add(testWaitWithSingleError());
249 futures.add(testWaitWithMultipleErrors()); 273 futures.add(testWaitWithMultipleErrors());
250 futures.add(testWaitWithMultipleErrorsEager()); 274 futures.add(testWaitWithMultipleErrorsEager());
251 futures.add(testWaitWithSingleErrorWithStackTrace()); 275 futures.add(testWaitWithSingleErrorWithStackTrace());
252 futures.add(testWaitWithMultipleErrorsWithStackTrace()); 276 futures.add(testWaitWithMultipleErrorsWithStackTrace());
253 futures.add(testWaitWithMultipleErrorsWithStackTraceEager()); 277 futures.add(testWaitWithMultipleErrorsWithStackTraceEager());
254 futures.add(testEagerWait()); 278 futures.add(testEagerWait());
255 futures.add(testForEachEmpty()); 279 futures.add(testForEachEmpty());
256 futures.add(testForEach()); 280 futures.add(testForEach());
257 futures.add(testForEachSync()); 281 futures.add(testForEachSync());
258 futures.add(testForEachWithException()); 282 futures.add(testForEachWithException());
259 futures.add(testDoWhile()); 283 futures.add(testDoWhile());
260 futures.add(testDoWhileSync()); 284 futures.add(testDoWhileSync());
261 futures.add(testDoWhileWithException()); 285 futures.add(testDoWhileWithException());
286 futures.add(testDoWhileManyFutures());
287 futures.add(testDoWhileManyValues());
262 288
263 asyncStart(); 289 asyncStart();
264 Future.wait(futures).then((List list) { 290 Future.wait(futures).then((List list) {
265 Expect.equals(18, list.length); 291 Expect.equals(20, list.length);
266 asyncEnd(); 292 asyncEnd();
267 }); 293 });
268 } 294 }
OLDNEW
« no previous file with comments | « sdk/lib/async/future.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698