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

Unified Diff: tests/kernel/unsorted/loop_test.dart

Issue 2451623006: Reland "Merge more Kernel infrastructure from kernel_sdk SDK fork." (Closed)
Patch Set: Fix Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/kernel/unsorted/local_function_test.dart ('k') | tests/kernel/unsorted/mapliteral_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/kernel/unsorted/loop_test.dart
diff --git a/tests/kernel/unsorted/loop_test.dart b/tests/kernel/unsorted/loop_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..bf487408d5813a05a7b6d187f6d620c14b9590ce
--- /dev/null
+++ b/tests/kernel/unsorted/loop_test.dart
@@ -0,0 +1,91 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Tests of loops.
+
+import 'expect.dart';
+
+fact(n) {
+ var f = 1;
+ while (n > 0) {
+ f *= n;
+ --n;
+ }
+ return f;
+}
+
+fib(n) {
+ if (n == 0) return 0;
+ var previous = 0, current = 1;
+ while (n > 1) {
+ var temp = current;
+ current += previous;
+ previous = temp;
+ --n;
+ }
+ return current;
+}
+
+mkTrue() => true;
+mkFalse() => false;
+
+check(b) {
+ Expect.isTrue(b);
+ return b;
+}
+
+test0() {
+ while (mkTrue()) {
+ Expect.isTrue(true);
+ return;
+ }
+ Expect.isTrue(false);
+}
+
+test1() {
+ while (mkFalse()) {
+ Expect.isTrue(false);
+ }
+ Expect.isTrue(true);
+}
+
+test2() {
+ do {
+ Expect.isTrue(true);
+ } while (mkFalse());
+ Expect.isTrue(true);
+}
+
+test3() {
+ do {
+ Expect.isTrue(true);
+ return;
+ } while (check(false));
+ Expect.isTrue(false);
+}
+
+main() {
+ Expect.isTrue(fact(0) == 1);
+ Expect.isTrue(fact(1) == 1);
+ Expect.isTrue(fact(5) == 120);
+ Expect.isTrue(fact(42) ==
+ 1405006117752879898543142606244511569936384000000000);
+ Expect.isTrue(fact(3.14159) == 1.0874982674320444);
+
+ Expect.isTrue(fib(0) == 0);
+ Expect.isTrue(fib(1) == 1);
+ Expect.isTrue(fib(2) == 1);
+ Expect.isTrue(fib(3) == 2);
+ Expect.isTrue(fib(4) == 3);
+ Expect.isTrue(fib(5) == 5);
+ Expect.isTrue(fib(6) == 8);
+ Expect.isTrue(fib(7) == 13);
+ Expect.isTrue(fib(42) == 267914296);
+ Expect.isTrue(fib(3.14159) == 3);
+
+ test0();
+ test1();
+ test2();
+ test3();
+}
« no previous file with comments | « tests/kernel/unsorted/local_function_test.dart ('k') | tests/kernel/unsorted/mapliteral_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698