Chromium Code Reviews| Index: tests/language/div_with_power_of_two_test.dart |
| =================================================================== |
| --- tests/language/div_with_power_of_two_test.dart (revision 0) |
| +++ tests/language/div_with_power_of_two_test.dart (revision 0) |
| @@ -0,0 +1,58 @@ |
| +// 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. |
| +// Test division by power of two. |
| +// Test that results before and after optimization are the same. |
| + |
| +class TestValue { |
| + final int argument; |
| + final int result; |
| + final Function function; |
| + TestValue(func, arg) : function = func, argument = arg, result = func(arg) {} |
|
Florian Schneider
2013/02/04 13:04:03
How do you prevent func from already being optimiz
srdjan
2013/02/04 19:02:33
Added expected values as well.
|
| +} |
| + |
| + |
| +divBy4(a) => a ~/ 4; |
| +divByNeg4(a) => a ~/ - 4; |
|
Florian Schneider
2013/02/04 13:04:03
Remove extra space after -
/s/- 4/-4/
srdjan
2013/02/04 19:02:33
Done.
|
| +divBy134217728(a) => a ~/ 134217728; |
| +divByNeg134217728(a) => a ~/ -134217728; |
| + |
|
Florian Schneider
2013/02/04 13:04:03
Please add tests for the special cases:
a ~/ 0
a
srdjan
2013/02/04 19:02:33
Done.
|
| +divBy4_(a) => a ~/ 4; |
| +divByNeg4_(a) => a ~/ - 4; |
|
Florian Schneider
2013/02/04 13:04:03
/s/- 4/-4/
srdjan
2013/02/04 19:02:33
Done.
|
| +divBy549755813888(a) => a ~/ 549755813888; |
| +divByNeg549755813888(a) => a ~/ -549755813888; |
| + |
| + |
| +test(dividends, testFunctions) { |
| + var tests = new List(); |
| + for (Function f in testFunctions) { |
| + for (int d in dividends) { |
| + tests.add(new TestValue(f, d)); |
| + } |
| + } |
| + // Optimize. |
| + for (int i = 0; i < 10000; i++) { |
| + for (var f in testFunctions) { |
| + f(10); |
| + } |
| + } |
| + |
| + for (var t in tests) { |
| + Expect.equals(t.result, t.function(t.argument)); |
| + } |
| +} |
| + |
| + |
| +main() { |
| + // 32 bits. |
| + var dividends = const [134217730, -134217730, 10, -10]; |
| + var testFunctions = const [divBy4, divByNeg4, |
| + divBy134217728, divByNeg134217728]; |
| + test(dividends, testFunctions); |
| + // 64 bits, use different functions, 64 bit arguments. |
| + dividends = const [549755813990, -549755813990, |
| + 288230925907525632, -288230925907525632]; |
| + testFunctions = const [divBy4_, divByNeg4_, |
| + divBy549755813888, divByNeg549755813888]; |
| + test(dividends, testFunctions); |
| +} |