Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test program to test arithmetic operations. | 4 // Dart test program to test arithmetic operations. |
| 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr | 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr |
| 6 | 6 |
| 7 library arithmetic_test; | 7 library arithmetic_test; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 | 10 |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 static int divMod(a, b) => a ~/ b + a % b; | 428 static int divMod(a, b) => a ~/ b + a % b; |
| 429 | 429 |
| 430 static void testSmiDivModDeopt() { | 430 static void testSmiDivModDeopt() { |
| 431 var a = -0x40000000; | 431 var a = -0x40000000; |
| 432 var b = -1; | 432 var b = -1; |
| 433 for (var i = 0; i < 10; i++) Expect.equals(0x40000000, divMod(a, b)); | 433 for (var i = 0; i < 10; i++) Expect.equals(0x40000000, divMod(a, b)); |
| 434 } | 434 } |
| 435 | |
| 436 static double sinCosSub(double a) => sin(a) - cos(a); | |
| 437 | |
| 438 static void testSinCos() { | |
|
Florian Schneider
2013/12/03 14:12:04
Maybe test a few more values like PI, PI/2 as done
srdjan
2013/12/03 18:10:01
Done.
| |
| 439 var e = sin(1.234) - cos(1.234); | |
| 440 for (var i = 0; i < 20; i++) { | |
| 441 Expect.approxEquals(e, sinCosSub(1.234)); | |
| 442 } | |
| 443 } | |
| 435 | 444 |
| 436 static mySqrt(var x) => sqrt(x); | 445 static mySqrt(var x) => sqrt(x); |
| 437 | 446 |
| 438 static testSqrtDeopt() { | 447 static testSqrtDeopt() { |
| 439 for (var i = 0; i < 10; i++) mySqrt(4.0); | 448 for (var i = 0; i < 10; i++) mySqrt(4.0); |
| 440 Expect.equals(2.0, mySqrt(4.0)); | 449 Expect.equals(2.0, mySqrt(4.0)); |
| 441 Expect.throws(() => mySqrt("abc")); | 450 Expect.throws(() => mySqrt("abc")); |
| 442 } | 451 } |
| 443 | 452 |
| 444 static self_equality(x) { | 453 static self_equality(x) { |
| 445 return x == x; | 454 return x == x; |
| 446 } | 455 } |
| 447 | 456 |
| 448 static testDoubleEquality() { | 457 static testDoubleEquality() { |
| 449 Expect.isFalse(self_equality(double.NAN)); | 458 Expect.isFalse(self_equality(double.NAN)); |
| 450 for (int i = 0; i < 20; i++) { | 459 for (int i = 0; i < 20; i++) { |
| 451 self_equality(3.0); | 460 self_equality(3.0); |
| 452 } | 461 } |
| 453 Expect.isFalse(self_equality(double.NAN)); | 462 Expect.isFalse(self_equality(double.NAN)); |
| 454 } | 463 } |
| 455 | 464 |
| 456 static testMain() { | 465 static testMain() { |
| 457 for (int i = 0; i < 20; i++) { | 466 for (int i = 0; i < 20; i++) { |
| 458 runOne(); | 467 runOne(); |
| 459 testSmiDivDeopt(); | 468 testSmiDivDeopt(); |
| 460 testSmiDivModDeopt(); | 469 testSmiDivModDeopt(); |
| 461 testSqrtDeopt(); | 470 testSqrtDeopt(); |
| 462 testDoubleEquality(); | 471 testDoubleEquality(); |
| 472 testSinCos(); | |
| 463 } | 473 } |
| 464 } | 474 } |
| 465 } | 475 } |
| 466 | 476 |
| 467 main() { | 477 main() { |
| 468 ArithmeticTest.testMain(); | 478 ArithmeticTest.testMain(); |
| 469 } | 479 } |
| OLD | NEW |