mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 23:31:42 +00:00
c5ff5b4011
Successfully migrated 28 tests. Need manual work on 1 test: - language_2/truncdiv_test.dart: (TODO) Merge from language/truncdiv_test.dart into this file. Bug: Change-Id: Iceba114915feba5ab4564b8b7265d684d23b4d0d Reviewed-on: https://dart-review.googlesource.com/12360 Commit-Queue: Janice Collins <jcollins@google.com> Reviewed-by: Janice Collins <jcollins@google.com> Reviewed-by: Jaime Wren <jwren@google.com>
35 lines
935 B
Dart
35 lines
935 B
Dart
// Copyright (c) 2013, 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.
|
|
// Dart test optimization of modulo operator on Smi.
|
|
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
main() {
|
|
for (int i = -30; i < 30; i++) {
|
|
Expect.equals(i % 9, foo(i, 9));
|
|
// Zero test is done outside the loop.
|
|
if (i < 0) {
|
|
Expect.equals(i ~/ -i, foo2(i));
|
|
} else if (i > 0) {
|
|
Expect.equals(i ~/ i, foo2(i));
|
|
}
|
|
}
|
|
Expect.throws(() => foo(12, 0), (e) => e is IntegerDivisionByZeroException);
|
|
Expect.throws(() => foo2(0), (e) => e is IntegerDivisionByZeroException);
|
|
}
|
|
|
|
foo(i, x) => i % x;
|
|
|
|
foo2(i) {
|
|
// Make sure x has a range computed.
|
|
var x = 0;
|
|
if (i < 0) {
|
|
x = -i;
|
|
} else {
|
|
x = i;
|
|
}
|
|
return i ~/ x;
|
|
}
|