| OLD | NEW |
| 1 // Copyright (c) 2011, 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 // Test basic integer operations. | 4 // Test basic integer operations. |
| 5 | 5 |
| 6 class ToStringAsFixedTest { | 6 class ToStringAsFixedTest { |
| 7 static void testMain() { | 7 static void testMain() { |
| 8 Expect.equals("2.000", 2.0.toStringAsFixed(3)); | 8 Expect.equals("2.000", 2.0.toStringAsFixed(3)); |
| 9 Expect.equals("2.100", 2.1.toStringAsFixed(3)); | 9 Expect.equals("2.100", 2.1.toStringAsFixed(3)); |
| 10 Expect.equals("2.120", 2.12.toStringAsFixed(3)); | 10 Expect.equals("2.120", 2.12.toStringAsFixed(3)); |
| 11 Expect.equals("2.123", 2.123.toStringAsFixed(3)); | 11 Expect.equals("2.123", 2.123.toStringAsFixed(3)); |
| 12 Expect.equals("2.124", 2.1239.toStringAsFixed(3)); | 12 Expect.equals("2.124", 2.1239.toStringAsFixed(3)); |
| 13 Expect.equals("NaN", (0.0 / 0.0).toStringAsFixed(3)); | 13 Expect.equals("NaN", (0.0 / 0.0).toStringAsFixed(3)); |
| 14 Expect.equals("Infinity", (1.0/0.0).toStringAsFixed(3)); | 14 Expect.equals("Infinity", (1.0/0.0).toStringAsFixed(3)); |
| 15 Expect.equals("-Infinity", (-1.0/0.0).toStringAsFixed(3)); | 15 Expect.equals("-Infinity", (-1.0/0.0).toStringAsFixed(3)); |
| 16 // TODO(floitsch): enable the following test when double.toString does the | 16 Expect.equals("1.1111111111111111e+21", 1111111111111111111111.0.toStringAsF
ixed(8)); |
| 17 // right thing. | |
| 18 // Expect.equals("1.1111111111111111e+21", 1111111111111111111111.0.toString
AsFixed(8)); | |
| 19 Expect.equals("0.1", 0.1.toStringAsFixed(1)); | 17 Expect.equals("0.1", 0.1.toStringAsFixed(1)); |
| 20 Expect.equals("0.10", 0.1.toStringAsFixed(2)); | 18 Expect.equals("0.10", 0.1.toStringAsFixed(2)); |
| 21 Expect.equals("0.100", 0.1.toStringAsFixed(3)); | 19 Expect.equals("0.100", 0.1.toStringAsFixed(3)); |
| 22 Expect.equals("0.01", 0.01.toStringAsFixed(2)); | 20 Expect.equals("0.01", 0.01.toStringAsFixed(2)); |
| 23 Expect.equals("0.010", 0.01.toStringAsFixed(3)); | 21 Expect.equals("0.010", 0.01.toStringAsFixed(3)); |
| 24 Expect.equals("0.0100", 0.01.toStringAsFixed(4)); | 22 Expect.equals("0.0100", 0.01.toStringAsFixed(4)); |
| 25 Expect.equals("0.00", 0.001.toStringAsFixed(2)); | 23 Expect.equals("0.00", 0.001.toStringAsFixed(2)); |
| 26 Expect.equals("0.001", 0.001.toStringAsFixed(3)); | 24 Expect.equals("0.001", 0.001.toStringAsFixed(3)); |
| 27 Expect.equals("0.0010", 0.001.toStringAsFixed(4)); | 25 Expect.equals("0.0010", 0.001.toStringAsFixed(4)); |
| 28 Expect.equals("1.0000", 1.0.toStringAsFixed(4)); | 26 Expect.equals("1.0000", 1.0.toStringAsFixed(4)); |
| 29 Expect.equals("1.0", 1.0.toStringAsFixed(1)); | 27 Expect.equals("1.0", 1.0.toStringAsFixed(1)); |
| 30 Expect.equals("1", 1.0.toStringAsFixed(0)); | 28 Expect.equals("1", 1.0.toStringAsFixed(0)); |
| 31 Expect.equals("12", 12.0.toStringAsFixed(0)); | 29 Expect.equals("12", 12.0.toStringAsFixed(0)); |
| 32 Expect.equals("1", 1.1.toStringAsFixed(0)); | 30 Expect.equals("1", 1.1.toStringAsFixed(0)); |
| 33 Expect.equals("12", 12.1.toStringAsFixed(0)); | 31 Expect.equals("12", 12.1.toStringAsFixed(0)); |
| 34 Expect.equals("1", 1.12.toStringAsFixed(0)); | 32 Expect.equals("1", 1.12.toStringAsFixed(0)); |
| 35 Expect.equals("12", 12.12.toStringAsFixed(0)); | 33 Expect.equals("12", 12.12.toStringAsFixed(0)); |
| 36 Expect.equals("0.0000006", 0.0000006.toStringAsFixed(7)); | 34 Expect.equals("0.0000006", 0.0000006.toStringAsFixed(7)); |
| 37 Expect.equals("0.00000006", 0.00000006.toStringAsFixed(8)); | 35 Expect.equals("0.00000006", 0.00000006.toStringAsFixed(8)); |
| 38 Expect.equals("0.000000060", 0.00000006.toStringAsFixed(9)); | 36 Expect.equals("0.000000060", 0.00000006.toStringAsFixed(9)); |
| 39 Expect.equals("0.0000000600", 0.00000006.toStringAsFixed(10)); | 37 Expect.equals("0.0000000600", 0.00000006.toStringAsFixed(10)); |
| 40 Expect.equals("0", 0.0.toStringAsFixed(0)); | 38 Expect.equals("0", 0.0.toStringAsFixed(0)); |
| 41 Expect.equals("0.0", 0.0.toStringAsFixed(1)); | 39 Expect.equals("0.0", 0.0.toStringAsFixed(1)); |
| 42 Expect.equals("0.00", 0.0.toStringAsFixed(2)); | 40 Expect.equals("0.00", 0.0.toStringAsFixed(2)); |
| 43 | 41 |
| 44 // TODO(floitsch): enable the following test when double.toString does the | |
| 45 // right thing. | |
| 46 // Expect.equals("-1.1111111111111111e+21", (-1111111111111111111111.0).toSt
ringAsFixed(8)); | |
| 47 Expect.equals("-0.1", (-0.1).toStringAsFixed(1)); | 42 Expect.equals("-0.1", (-0.1).toStringAsFixed(1)); |
| 48 Expect.equals("-0.10", (-0.1).toStringAsFixed(2)); | 43 Expect.equals("-0.10", (-0.1).toStringAsFixed(2)); |
| 49 Expect.equals("-0.100", (-0.1).toStringAsFixed(3)); | 44 Expect.equals("-0.100", (-0.1).toStringAsFixed(3)); |
| 50 Expect.equals("-0.01", (-0.01).toStringAsFixed(2)); | 45 Expect.equals("-0.01", (-0.01).toStringAsFixed(2)); |
| 51 Expect.equals("-0.010", (-0.01).toStringAsFixed(3)); | 46 Expect.equals("-0.010", (-0.01).toStringAsFixed(3)); |
| 52 Expect.equals("-0.0100", (-0.01).toStringAsFixed(4)); | 47 Expect.equals("-0.0100", (-0.01).toStringAsFixed(4)); |
| 53 Expect.equals("-0.00", (-0.001).toStringAsFixed(2)); | 48 Expect.equals("-0.00", (-0.001).toStringAsFixed(2)); |
| 54 Expect.equals("-0.001", (-0.001).toStringAsFixed(3)); | 49 Expect.equals("-0.001", (-0.001).toStringAsFixed(3)); |
| 55 Expect.equals("-0.0010", (-0.001).toStringAsFixed(4)); | 50 Expect.equals("-0.0010", (-0.001).toStringAsFixed(4)); |
| 56 Expect.equals("-1.0000", (-1.0).toStringAsFixed(4)); | 51 Expect.equals("-1.0000", (-1.0).toStringAsFixed(4)); |
| 57 Expect.equals("-1.0", (-1.0).toStringAsFixed(1)); | 52 Expect.equals("-1.0", (-1.0).toStringAsFixed(1)); |
| 58 Expect.equals("-1", (-1.0).toStringAsFixed(0)); | 53 Expect.equals("-1", (-1.0).toStringAsFixed(0)); |
| 59 Expect.equals("-1", (-1.1).toStringAsFixed(0)); | 54 Expect.equals("-1", (-1.1).toStringAsFixed(0)); |
| 60 Expect.equals("-12", (-12.1).toStringAsFixed(0)); | 55 Expect.equals("-12", (-12.1).toStringAsFixed(0)); |
| 61 Expect.equals("-1", (-1.12).toStringAsFixed(0)); | 56 Expect.equals("-1", (-1.12).toStringAsFixed(0)); |
| 62 Expect.equals("-12", (-12.12).toStringAsFixed(0)); | 57 Expect.equals("-12", (-12.12).toStringAsFixed(0)); |
| 63 Expect.equals("-0.0000006", (-0.0000006).toStringAsFixed(7)); | 58 Expect.equals("-0.0000006", (-0.0000006).toStringAsFixed(7)); |
| 64 Expect.equals("-0.00000006", (-0.00000006).toStringAsFixed(8)); | 59 Expect.equals("-0.00000006", (-0.00000006).toStringAsFixed(8)); |
| 65 Expect.equals("-0.000000060", (-0.00000006).toStringAsFixed(9)); | 60 Expect.equals("-0.000000060", (-0.00000006).toStringAsFixed(9)); |
| 66 Expect.equals("-0.0000000600", (-0.00000006).toStringAsFixed(10)); | 61 Expect.equals("-0.0000000600", (-0.00000006).toStringAsFixed(10)); |
| 67 Expect.equals("0", (-0.0).toStringAsFixed(0)); | 62 Expect.equals("-0", (-0.0).toStringAsFixed(0)); |
| 68 Expect.equals("0.0", (-0.0).toStringAsFixed(1)); | 63 Expect.equals("-0.0", (-0.0).toStringAsFixed(1)); |
| 69 Expect.equals("0.00", (-0.0).toStringAsFixed(2)); | 64 Expect.equals("-0.00", (-0.0).toStringAsFixed(2)); |
| 70 | 65 |
| 71 Expect.equals("1000", 1000.0.toStringAsFixed(0)); | 66 Expect.equals("1000", 1000.0.toStringAsFixed(0)); |
| 72 Expect.equals("0", 0.00001.toStringAsFixed(0)); | 67 Expect.equals("0", 0.00001.toStringAsFixed(0)); |
| 73 Expect.equals("0.00001", 0.00001.toStringAsFixed(5)); | 68 Expect.equals("0.00001", 0.00001.toStringAsFixed(5)); |
| 74 Expect.equals("0.00000000000000000010", 0.0000000000000000001.toStringAsFixe
d(20)); | 69 Expect.equals("0.00000000000000000010", 0.0000000000000000001.toStringAsFixe
d(20)); |
| 75 Expect.equals("0.00001000000000000", 0.00001.toStringAsFixed(17)); | 70 Expect.equals("0.00001000000000000", 0.00001.toStringAsFixed(17)); |
| 76 Expect.equals("1.00000000000000000", 1.0.toStringAsFixed(17)); | 71 Expect.equals("1.00000000000000000", 1.0.toStringAsFixed(17)); |
| 77 Expect.equals("1000000000000000128", 1000000000000000128.0.toStringAsFixed(0
)); | 72 Expect.equals("1000000000000000128", 1000000000000000128.0.toStringAsFixed(0
)); |
| 78 Expect.equals("100000000000000128.0", 100000000000000128.0.toStringAsFixed(1
)); | 73 Expect.equals("100000000000000128.0", 100000000000000128.0.toStringAsFixed(1
)); |
| 79 Expect.equals("10000000000000128.00", 10000000000000128.0.toStringAsFixed(2)
); | 74 Expect.equals("10000000000000128.00", 10000000000000128.0.toStringAsFixed(2)
); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 108 } | 103 } |
| 109 Expect.equals(true, thrown); | 104 Expect.equals(true, thrown); |
| 110 } | 105 } |
| 111 } | 106 } |
| 112 } | 107 } |
| 113 | 108 |
| 114 | 109 |
| 115 main() { | 110 main() { |
| 116 ToStringAsFixedTest.testMain(); | 111 ToStringAsFixedTest.testMain(); |
| 117 } | 112 } |
| OLD | NEW |