Index: tests/language/arithmetic_test.dart |
diff --git a/tests/language/arithmetic_test.dart b/tests/language/arithmetic_test.dart |
index 39a8b893728eebbd6ea8b522b456e81e98835278..80be7f901ea2d31522a9d0ad6525c0c48be824af 100644 |
--- a/tests/language/arithmetic_test.dart |
+++ b/tests/language/arithmetic_test.dart |
@@ -30,7 +30,7 @@ class ArithmeticTest { |
// No exception allowed for parse double. |
double d = double.parse(str); |
try { |
- var a = d.toInt(); |
+ var a = d.truncate(); |
return false; |
} on FormatException catch (e) { |
return true; |
@@ -61,7 +61,7 @@ class ArithmeticTest { |
Expect.equals(26.0, a + b); |
Expect.equals(18.0, a - b); |
Expect.equals(88.0, a * b); |
- Expect.equals(5.0, a ~/ b); |
+ Expect.equals(5, a ~/ b); |
Expect.equals(5.5, a / b); |
Expect.equals(2.0, a % b); |
Expect.equals(2.0, a.remainder(b)); |
@@ -71,7 +71,7 @@ class ArithmeticTest { |
Expect.equals(26.0, a + b); |
Expect.equals(18.0, a - b); |
Expect.equals(88.0, a * b); |
- Expect.equals(5.0, a ~/ b); |
+ Expect.equals(5, a ~/ b); |
Expect.equals(5.5, a / b); |
Expect.equals(2.0, a % b); |
Expect.equals(2.0, a.remainder(b)); |
@@ -81,7 +81,7 @@ class ArithmeticTest { |
Expect.equals(26.0, a + b); |
Expect.equals(18.0, a - b); |
Expect.equals(88.0, a * b); |
- Expect.equals(5.0, a ~/ b); |
+ Expect.equals(5, a ~/ b); |
Expect.equals(5.5, a / b); |
Expect.equals(2.0, a % b); |
Expect.equals(2.0, a.remainder(b)); |
@@ -206,16 +206,15 @@ class ArithmeticTest { |
Expect.equals(big, big.ceil()); |
Expect.equals(-big, (-big).ceil()); |
// Double. |
- Expect.equals(0.0, (0.0).ceil()); |
+ Expect.equals(0, (0.0).ceil()); |
Expect.equals(false, (0.0).ceil().isNegative); |
- Expect.equals(1.0, (0.1).ceil()); |
- Expect.equals(-0.0, (-0.0).ceil()); |
- Expect.equals(-0.0, (-0.3).ceil()); |
- // TODO(srdjan): enable the following tests once isNegative works. |
- // Expect.equals(true, (-0.0).ceil().isNegative); |
- // Expect.equals(true, (-0.3).ceil().isNegative); |
- Expect.equals(3.0, (2.1).ceil()); |
- Expect.equals(-2.0, (-2.1).ceil()); |
+ Expect.equals(1, (0.1).ceil()); |
+ Expect.equals(0, (-0.0).ceil()); |
+ Expect.equals(0, (-0.3).ceil()); |
+ Expect.isTrue((-0.0).ceil() is int); |
+ Expect.isTrue((-0.3).ceil() is int); |
+ Expect.equals(3, (2.1).ceil()); |
+ Expect.equals(-2, (-2.1).ceil()); |
// -- floor --. |
// Smi. |
@@ -226,16 +225,15 @@ class ArithmeticTest { |
Expect.equals(big, big.floor()); |
Expect.equals(-big, (-big).floor()); |
// Double. |
- Expect.equals(0.0, (0.0).floor()); |
- Expect.equals(0.0, (0.1).floor()); |
- Expect.equals(false, (0.0).floor().isNegative); |
- Expect.equals(false, (0.1).floor().isNegative); |
- Expect.equals(-0.0, (-0.0).floor()); |
- // TODO(srdjan): enable the following tests once isNegative works. |
- // Expect.equals(true, (-0.0).floor().isNegative); |
- Expect.equals(-1.0, (-0.1).floor()); |
- Expect.equals(2.0, (2.1).floor()); |
- Expect.equals(-3.0, (-2.1).floor()); |
+ Expect.equals(0, (0.0).floor()); |
+ Expect.equals(0, (0.1).floor()); |
+ Expect.isTrue((0.0).floor() is int); |
+ Expect.isTrue((0.1).floor() is int); |
+ Expect.equals(0, (-0.0).floor()); |
+ Expect.isTrue((-0.0).floor() is int); |
+ Expect.equals(-1, (-0.1).floor()); |
+ Expect.equals(2, (2.1).floor()); |
+ Expect.equals(-3, (-2.1).floor()); |
// -- truncate --. |
// Smi. |
@@ -246,20 +244,19 @@ class ArithmeticTest { |
Expect.equals(big, big.truncate()); |
Expect.equals(-big, (-big).truncate()); |
// Double. |
- Expect.equals(0.0, (0.0).truncate()); |
- Expect.equals(0.0, (0.1).truncate()); |
- Expect.equals(false, (0.0).truncate().isNegative); |
- Expect.equals(false, (0.1).truncate().isNegative); |
- Expect.equals(-0.0, (-0.0).truncate()); |
- Expect.equals(-0.0, (-0.3).truncate()); |
- // TODO(srdjan): enable the following tests once isNegative works. |
- // Expect.equals(true, (-0.0).truncate().isNegative); |
- // Expect.equals(true, (-0.3).truncate().isNegative); |
- Expect.equals(2.0, (2.1).truncate()); |
- Expect.equals(-2.0, (-2.1).truncate()); |
- |
- double b1 = (1234567890123.0).truncate(); |
- double b2 = (1234567890124.0).truncate(); |
+ Expect.equals(0, (0.0).truncate()); |
+ Expect.equals(0, (0.1).truncate()); |
+ Expect.isTrue((0.0).truncate() is int); |
+ Expect.isTrue((0.1).truncate() is int); |
+ Expect.equals(0, (-0.0).truncate()); |
+ Expect.equals(0, (-0.3).truncate()); |
+ Expect.isTrue((-0.0).truncate() is int); |
+ Expect.isTrue((-0.3).truncate() is int); |
+ Expect.equals(2, (2.1).truncate()); |
+ Expect.equals(-2, (-2.1).truncate()); |
+ |
+ int b1 = (1234567890123.0).truncate(); |
+ int b2 = (1234567890124.0).truncate(); |
Expect.equals(b2, b1 + 1.0); |
// -- round --. |
@@ -271,59 +268,53 @@ class ArithmeticTest { |
Expect.equals(big, big.round()); |
Expect.equals(-big, (-big).round()); |
// Double. |
- Expect.equals(3.0, (2.6).round()); |
- Expect.equals(-3.0, (-2.6).round()); |
- Expect.equals(0.0, (0.0).round()); |
- Expect.equals(0.0, (0.1).round()); |
- Expect.equals(false, (0.0).round().isNegative); |
- Expect.equals(false, (0.1).round().isNegative); |
- Expect.equals(-0.0, (-0.0).round()); |
- Expect.equals(-0.0, (-0.3).round()); |
- Expect.equals(2.0, (2.1).round()); |
- Expect.equals(-2.0, (-2.1).round()); |
- Expect.equals(1.0, (0.5).round()); |
- // TODO(floitsch): enable or adapt test, once we reached conclusion on |
- // b/4539188. |
- // Expect.equals(-0.0, (-0.5).round()); |
- // TODO(srdjan): enable the following tests once isNegative works. |
- // Expect.equals(true, (-0.0).round().isNegative); |
- // Expect.equals(true, (-0.3).round().isNegative); |
- // Expect.equals(true, (-0.5).round().isNegative); |
- Expect.equals(2.0, (1.5).round()); |
- // TODO(floitsch): enable or adapt test, once we reached conclusion on |
- // b/4539188. |
- // Expect.equals(-1.0, (-1.5).round()); |
- Expect.equals(1.0, (0.99).round()); |
+ Expect.equals(3, (2.6).round()); |
+ Expect.equals(-3, (-2.6).round()); |
+ Expect.equals(0, (0.0).round()); |
+ Expect.equals(0, (0.1).round()); |
+ Expect.isFalse((0.0).round().isNegative); |
+ Expect.isFalse((0.1).round().isNegative); |
+ Expect.equals(0, (-0.0).round()); |
+ Expect.equals(0, (-0.3).round()); |
+ Expect.equals(2, (2.1).round()); |
+ Expect.equals(-2, (-2.1).round()); |
+ Expect.equals(1, (0.5).round()); |
+ Expect.isTrue((-0.0).round() is int); |
+ Expect.isTrue((-0.3).round() is int); |
+ Expect.isTrue((-0.5).round() is int); |
+ Expect.equals(2, (1.5).round()); |
+ Expect.equals(-2, (-1.5).round()); |
+ Expect.equals(1, (0.99).round()); |
// -- toInt --. |
// Smi. |
- Expect.equals(0, (0).toInt()); |
- Expect.equals(1, (1).toInt()); |
- Expect.equals(-1, (-1).toInt()); |
+ Expect.equals(0, (0).truncate()); |
+ Expect.equals(1, (1).truncate()); |
+ Expect.equals(-1, (-1).truncate()); |
// Type checks. |
- { int i = (0).toInt(); } |
- { int i = (1).toInt(); } |
- { int i = (-1).toInt(); } |
+ { int i = (0).truncate(); } |
+ { int i = (1).truncate(); } |
+ { int i = (-1).truncate(); } |
// Big. |
- Expect.equals(big, big.toInt()); |
- Expect.equals(-big, (-big).toInt()); |
- { int i = big.toInt(); } |
- { int i = (-big).toInt(); } |
+ Expect.equals(big, big.truncate()); |
+ Expect.equals(-big, (-big).truncate()); |
+ { int i = big.truncate(); } |
+ { int i = (-big).truncate(); } |
// Double. |
- Expect.equals(1234567890123, (1234567890123.0).toInt()); |
- Expect.equals(-1234567890123, (-1234567890123.0).toInt()); |
- { int i = (1234567890123.0).toInt(); } |
- { int i = (-1234567890123.0).toInt(); } |
+ Expect.equals(1234567890123, (1234567890123.0).truncate()); |
+ Expect.equals(-1234567890123, (-1234567890123.0).truncate()); |
+ { int i = (1234567890123.0).truncate(); } |
+ { int i = (-1234567890123.0).truncate(); } |
// 32bit Smi border cases. |
- Expect.equals(-1073741824, (-1073741824.0).toInt()); |
- Expect.equals(-1073741825, (-1073741825.0).toInt()); |
- Expect.equals(1073741823, (1073741823.0).toInt()); |
- Expect.equals(1073741824, (1073741824.0).toInt()); |
+ Expect.equals(-1073741824, (-1073741824.0).truncate()); |
+ Expect.equals(-1073741825, (-1073741825.0).truncate()); |
+ Expect.equals(1073741823, (1073741823.0).truncate()); |
+ Expect.equals(1073741824, (1073741824.0).truncate()); |
- { int i = (-1073741824.0).toInt(); } |
- { int i = (-1073741825.0).toInt(); } |
- { int i = (1073741823.0).toInt(); } |
- { int i = (1073741824.0).toInt(); } |
+ { int i = (-1073741824.0).truncate(); } |
+ { int i = (-1073741825.0).truncate(); } |
+ { int i = (1073741823.0).truncate(); } |
+ { int i = (1073741824.0).truncate(); } |
// -- toDouble --. |
// Smi. |
@@ -335,10 +326,10 @@ class ArithmeticTest { |
{ double d = (1).toDouble(); } |
{ double d = (-1).toDouble(); } |
// Big. |
- Expect.equals(big, big.toInt()); |
- Expect.equals(-big, (-big).toInt()); |
- { int i = big.toInt(); } |
- { int i = (-big).toInt(); } |
+ Expect.equals(big, big.truncate()); |
+ Expect.equals(-big, (-big).truncate()); |
+ { int i = big.truncate(); } |
+ { int i = (-big).truncate(); } |
// Math functions. |
Expect.equals(2.0, sqrt(4.0)); |