OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Dart test program for testing do while statement. | |
5 | |
6 class Helper { | |
7 static int f1(bool b) { | |
8 do return 1; | |
9 while (b); | |
10 return 2; | |
11 } | |
12 | |
13 static int f2(bool b) { | |
14 do { | |
15 return 1; | |
16 } while (b); | |
17 return 2; | |
18 } | |
19 | |
20 static int f3(bool b) { | |
21 do | |
22 ; | |
23 while (b); | |
24 return 2; | |
25 } | |
26 | |
27 static int f4(bool b) { | |
28 do { | |
29 } while (b); | |
30 return 2; | |
31 } | |
32 | |
33 static int f5(int n) { | |
34 int i = 0; | |
35 do { | |
36 i++; | |
37 } while (i < n); | |
38 return i; | |
39 } | |
40 } | |
41 | |
42 class DoWhileTest { | |
43 static testMain() { | |
44 Expect.equals(1, Helper.f1(true)); | |
45 Expect.equals(1, Helper.f1(false)); | |
46 Expect.equals(1, Helper.f2(true)); | |
47 Expect.equals(1, Helper.f2(false)); | |
48 Expect.equals(2, Helper.f3(false)); | |
49 Expect.equals(2, Helper.f4(false)); | |
50 Expect.equals(1, Helper.f5(-2)); | |
51 Expect.equals(1, Helper.f5(-1)); | |
52 Expect.equals(1, Helper.f5(0)); | |
53 Expect.equals(1, Helper.f5(1)); | |
54 Expect.equals(2, Helper.f5(2)); | |
55 Expect.equals(3, Helper.f5(3)); | |
56 } | |
57 } | |
58 | |
59 main() { | |
60 DoWhileTest.testMain(); | |
61 } | |
OLD | NEW |