| 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() { |
| 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 Expect.approxEquals(1.0, sinCosSub(3.14159265)); |
| 444 Expect.approxEquals(1.0, sinCosSub(3.14159265 / 2.0)); |
| 445 } |
| 435 | 446 |
| 436 static mySqrt(var x) => sqrt(x); | 447 static mySqrt(var x) => sqrt(x); |
| 437 | 448 |
| 438 static testSqrtDeopt() { | 449 static testSqrtDeopt() { |
| 439 for (var i = 0; i < 10; i++) mySqrt(4.0); | 450 for (var i = 0; i < 10; i++) mySqrt(4.0); |
| 440 Expect.equals(2.0, mySqrt(4.0)); | 451 Expect.equals(2.0, mySqrt(4.0)); |
| 441 Expect.throws(() => mySqrt("abc")); | 452 Expect.throws(() => mySqrt("abc")); |
| 442 } | 453 } |
| 443 | 454 |
| 444 static self_equality(x) { | 455 static self_equality(x) { |
| 445 return x == x; | 456 return x == x; |
| 446 } | 457 } |
| 447 | 458 |
| 448 static testDoubleEquality() { | 459 static testDoubleEquality() { |
| 449 Expect.isFalse(self_equality(double.NAN)); | 460 Expect.isFalse(self_equality(double.NAN)); |
| 450 for (int i = 0; i < 20; i++) { | 461 for (int i = 0; i < 20; i++) { |
| 451 self_equality(3.0); | 462 self_equality(3.0); |
| 452 } | 463 } |
| 453 Expect.isFalse(self_equality(double.NAN)); | 464 Expect.isFalse(self_equality(double.NAN)); |
| 454 } | 465 } |
| 455 | 466 |
| 456 static testMain() { | 467 static testMain() { |
| 457 for (int i = 0; i < 20; i++) { | 468 for (int i = 0; i < 20; i++) { |
| 458 runOne(); | 469 runOne(); |
| 459 testSmiDivDeopt(); | 470 testSmiDivDeopt(); |
| 460 testSmiDivModDeopt(); | 471 testSmiDivModDeopt(); |
| 461 testSqrtDeopt(); | 472 testSqrtDeopt(); |
| 462 testDoubleEquality(); | 473 testDoubleEquality(); |
| 474 testSinCos(); |
| 463 } | 475 } |
| 464 } | 476 } |
| 465 } | 477 } |
| 466 | 478 |
| 467 main() { | 479 main() { |
| 468 ArithmeticTest.testMain(); | 480 ArithmeticTest.testMain(); |
| 469 } | 481 } |
| OLD | NEW |