| OLD | NEW |
| 1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import 'dart:fletch'; | 5 import 'dart:dartino'; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 testRecursion(0); | 10 testRecursion(0); |
| 11 testRecursion(10); | 11 testRecursion(10); |
| 12 testRecursion(100); | 12 testRecursion(100); |
| 13 testRecursion(1000); | 13 testRecursion(1000); |
| 14 } | 14 } |
| 15 | 15 |
| 16 void testRecursion(n) { | 16 void testRecursion(n) { |
| 17 var co = new Coroutine(recurse); | 17 var co = new Coroutine(recurse); |
| 18 Expect.isTrue(co.isSuspended); | 18 Expect.isTrue(co.isSuspended); |
| 19 Expect.equals(42, co(n)); | 19 Expect.equals(42, co(n)); |
| 20 Expect.equals(87, co(87)); | 20 Expect.equals(87, co(87)); |
| 21 Expect.equals(99, co(42)); | 21 Expect.equals(99, co(42)); |
| 22 Expect.isTrue(co.isDone); | 22 Expect.isTrue(co.isDone); |
| 23 } | 23 } |
| 24 | 24 |
| 25 int recurse(n) { | 25 int recurse(n) { |
| 26 if (n == 0) { | 26 if (n == 0) { |
| 27 Expect.equals(87, Coroutine.yield(42)); | 27 Expect.equals(87, Coroutine.yield(42)); |
| 28 Expect.equals(42, Coroutine.yield(87)); | 28 Expect.equals(42, Coroutine.yield(87)); |
| 29 return 99; | 29 return 99; |
| 30 } else { | 30 } else { |
| 31 return recurse(n - 1); | 31 return recurse(n - 1); |
| 32 } | 32 } |
| 33 } | 33 } |
| OLD | NEW |