OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 | |
8 baz() {} | 7 baz() {} |
9 | 8 |
10 loop1(x) { | 9 loop1(x) { |
11 var n = 0; | 10 var n = 0; |
12 while (n < x) { | 11 while (n < x) { |
13 n = n + 1; | 12 n = n + 1; |
14 } | 13 } |
15 return n; | 14 return n; |
16 } | 15 } |
17 | 16 |
18 loop2(x) { | 17 loop2(x) { |
19 var n = 0; | 18 var n = 0; |
20 if (x < 100) { | 19 if (x < 100) { |
21 while (n < x) { | 20 while (n < x) { |
22 n = n + 1; | 21 n = n + 1; |
23 } | |
24 } | 22 } |
25 baz(); | 23 } |
26 return n; | 24 baz(); |
| 25 return n; |
27 } | 26 } |
28 | 27 |
29 loop3(x) { | 28 loop3(x) { |
30 var n = 0; | 29 var n = 0; |
31 if (x < 100) { | 30 if (x < 100) { |
32 while (n < x) { | 31 while (n < x) { |
33 n = n + 1; | 32 n = n + 1; |
34 baz(); | 33 baz(); |
35 } | |
36 } | 34 } |
37 baz(); | 35 } |
38 return n; | 36 baz(); |
| 37 return n; |
39 } | 38 } |
40 | 39 |
41 loop4(x) { | 40 loop4(x) { |
42 var n = 0; | 41 var n = 0; |
43 if (x < 100) { | 42 if (x < 100) { |
44 while (n < x) { | 43 while (n < x) { |
45 baz(); | 44 baz(); |
46 n = n + 1; | 45 n = n + 1; |
47 } | |
48 } | 46 } |
49 baz(); | 47 } |
50 return n; | 48 baz(); |
| 49 return n; |
51 } | 50 } |
52 | 51 |
53 f1(b) { | 52 f1(b) { |
54 while (b) | 53 while (b) return 1; |
55 return 1; | |
56 | 54 |
57 return 2; | 55 return 2; |
58 } | 56 } |
59 | 57 |
60 f2(b) { | 58 f2(b) { |
61 while (b) { | 59 while (b) { |
62 return 1; | 60 return 1; |
63 } | 61 } |
64 return 2; | 62 return 2; |
65 } | 63 } |
66 | 64 |
67 main() { | 65 main() { |
68 Expect.equals(0, loop1(-10)); | 66 Expect.equals(0, loop1(-10)); |
69 Expect.equals(10, loop1(10)); | 67 Expect.equals(10, loop1(10)); |
70 | 68 |
71 Expect.equals(0, loop2(-10)); | 69 Expect.equals(0, loop2(-10)); |
72 Expect.equals(10, loop2(10)); | 70 Expect.equals(10, loop2(10)); |
73 Expect.equals(0, loop2(200)); | 71 Expect.equals(0, loop2(200)); |
74 | 72 |
75 Expect.equals(0, loop3(-10)); | 73 Expect.equals(0, loop3(-10)); |
76 Expect.equals(10, loop3(10)); | 74 Expect.equals(10, loop3(10)); |
77 Expect.equals(0, loop3(200)); | 75 Expect.equals(0, loop3(200)); |
78 | 76 |
79 Expect.equals(0, loop4(-10)); | 77 Expect.equals(0, loop4(-10)); |
80 Expect.equals(10, loop4(10)); | 78 Expect.equals(10, loop4(10)); |
81 Expect.equals(0, loop4(200)); | 79 Expect.equals(0, loop4(200)); |
82 | 80 |
83 Expect.equals(1, f1(true)); | 81 Expect.equals(1, f1(true)); |
84 Expect.equals(2, f1(false)); | 82 Expect.equals(2, f1(false)); |
85 Expect.equals(1, f2(true)); | 83 Expect.equals(1, f2(true)); |
86 Expect.equals(2, f2(false)); | 84 Expect.equals(2, f2(false)); |
87 } | 85 } |
OLD | NEW |