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

Unified Diff: tests/language/fannkuch_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
Index: tests/language/fannkuch_test.dart
diff --git a/tests/language/fannkuch_test.dart b/tests/language/fannkuch_test.dart
index ffde845b23d6fb12befbcbd983dbeecb279d10b8..3505f6021dda337d8922f5998418809c92ad04d4 100644
--- a/tests/language/fannkuch_test.dart
+++ b/tests/language/fannkuch_test.dart
@@ -12,16 +12,21 @@ class FannkuchTest {
static fannkuch(n) {
var p = new List(n), q = new List(n), s = new List(n);
var sign = 1, maxflips = 0, sum = 0, m = n - 1;
- for (var i = 0; i < n; i++) { p[i] = i; q[i] = i; s[i] = i; }
+ for (var i = 0; i < n; i++) {
+ p[i] = i;
+ q[i] = i;
+ s[i] = i;
+ }
do {
// Copy and flip.
- var q0 = p[0]; // Cache 0th element.
+ var q0 = p[0]; // Cache 0th element.
if (q0 != 0) {
- for (var i = 1; i < n; i++) q[i] = p[i]; // Work on a copy.
+ for (var i = 1; i < n; i++) q[i] = p[i]; // Work on a copy.
var flips = 1;
do {
var qq = q[q0];
- if (qq == 0) { // ... until 0th element is 0.
+ if (qq == 0) {
+ // ... until 0th element is 0.
sum += sign * flips;
if (flips > maxflips) maxflips = flips; // New maximum?
break;
@@ -29,30 +34,45 @@ class FannkuchTest {
q[q0] = q0;
if (q0 >= 3) {
var i = 1, j = q0 - 1, t;
- do { t = q[i]; q[i] = q[j]; q[j] = t; i++; j--; } while (i < j);
+ do {
+ t = q[i];
+ q[i] = q[j];
+ q[j] = t;
+ i++;
+ j--;
+ } while (i < j);
}
- q0 = qq; flips++;
+ q0 = qq;
+ flips++;
} while (true);
}
if (sign == 1) {
- var t = p[1]; p[1] = p[0]; p[0] = t; sign = -1; // Rotate 0<-1.
+ var t = p[1];
+ p[1] = p[0];
+ p[0] = t;
+ sign = -1; // Rotate 0<-1.
} else {
// Rotate 0<-1 and 0<-1<-2.
var t = p[1];
p[1] = p[2];
p[2] = t;
sign = 1;
- for(var i = 2; i < n; i++) {
+ for (var i = 2; i < n; i++) {
var sx = s[i];
- if (sx != 0) { s[i] = sx-1; break; }
+ if (sx != 0) {
+ s[i] = sx - 1;
+ break;
+ }
if (i == m) {
- return [sum, maxflips];
+ return [sum, maxflips];
}
s[i] = i;
// Rotate 0<-...<-i+1.
t = p[0];
- for(var j=0; j<=i; j++) { p[j] = p[j+1]; }
- p[i+1] = t;
+ for (var j = 0; j <= i; j++) {
+ p[j] = p[j + 1];
+ }
+ p[i + 1] = t;
}
}
} while (true);
@@ -66,6 +86,7 @@ class FannkuchTest {
print("${pf[0]}\nPfannkuchen($n) = ${pf[1]}");
}
}
+
main() {
FannkuchTest.testMain();
}

Powered by Google App Engine
This is Rietveld 408576698