dart-sdk/tests/language/osr_test.dart
Jacob Richman 2dcd56ef43 Format all tests.
There are far too many files here to review everyone carefully.
Spot checking most of the diffs look good as test code is generally written
with less care than application code so lots of ugly formatting get through.
If people notice files where the automated formatting bothers them feel free
to comment indicating file names and I'll move spaces within comments to make
the formatting cleaner and use comments to force block formatting as I have
done for other case where formatting looked bad.

BUG=
R=efortuna@google.com

Review-Url: https://codereview.chromium.org/2771453003 .
2017-04-17 14:53:02 -07:00

96 lines
2.1 KiB
Dart

// Copyright (c) 2014, 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.
// VMOptions=--optimization-counter-threshold=5 --no-background-compilation
// Test correct OSR (issue 16151).
import "dart:collection";
import "package:expect/expect.dart";
List create([int length]) {
return new MyList(length);
}
main() {
test(create);
}
class MyList<E> extends ListBase<E> {
List<E> _list;
MyList([int length])
: _list = (length == null ? new List() : new List(length));
E operator [](int index) => _list[index];
void operator []=(int index, E value) {
_list[index] = value;
}
int get length => _list.length;
void set length(int newLength) {
_list.length = newLength;
}
}
test(List create([int length])) {
sort_A01_t02_test(create);
}
// From library co19 sort_A01_t02.
sort_A01_t02_test(List create([int length])) {
int c(var a, var b) {
return a < b ? -1 : (a == b ? 0 : 1);
}
int maxlen = 7;
int prevLength = 0;
for (int length = 1; length < maxlen; ++length) {
// Check that we are making progress.
if (prevLength == length) {
// Cannot use Expect.notEquals since it hides the bug.
throw "No progress made";
}
prevLength = length;
List a = create(length);
List expected = create(length);
for (int i = 0; i < length; ++i) {
expected[i] = i;
a[i] = i;
}
void swap(int i, int j) {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
void check() {
return;
// Deleting the code below will throw a RangeError instead of throw above.
var a_copy = new List(length);
a_copy.setRange(0, length, a);
a_copy.sort(c);
}
void permute(int n) {
if (n == 1) {
check();
} else {
for (int i = 0; i < n; i++) {
permute(n - 1);
if (n % 2 == 1) {
swap(0, n - 1);
} else {
swap(i, n - 1);
}
}
}
} //void permute
permute(length);
} //for i in 0..length
} // test