OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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)); |
(...skipping 23 matching lines...) Expand all Loading... | |
34 Expect.equals("12", 12.12.toStringAsFixed(0)); | 34 Expect.equals("12", 12.12.toStringAsFixed(0)); |
35 Expect.equals("0.0000006", 0.0000006.toStringAsFixed(7)); | 35 Expect.equals("0.0000006", 0.0000006.toStringAsFixed(7)); |
36 Expect.equals("0.00000006", 0.00000006.toStringAsFixed(8)); | 36 Expect.equals("0.00000006", 0.00000006.toStringAsFixed(8)); |
37 Expect.equals("0.000000060", 0.00000006.toStringAsFixed(9)); | 37 Expect.equals("0.000000060", 0.00000006.toStringAsFixed(9)); |
38 Expect.equals("0.0000000600", 0.00000006.toStringAsFixed(10)); | 38 Expect.equals("0.0000000600", 0.00000006.toStringAsFixed(10)); |
39 Expect.equals("0", 0.0.toStringAsFixed(0)); | 39 Expect.equals("0", 0.0.toStringAsFixed(0)); |
40 Expect.equals("0.0", 0.0.toStringAsFixed(1)); | 40 Expect.equals("0.0", 0.0.toStringAsFixed(1)); |
41 Expect.equals("0.00", 0.0.toStringAsFixed(2)); | 41 Expect.equals("0.00", 0.0.toStringAsFixed(2)); |
42 | 42 |
43 // FIXME: currently bigint formatting produces hexes. | 43 // FIXME: currently bigint formatting produces hexes. |
44 // Expect.equals("-1.1111111111111111e+21", (-1111111111111111111111.0).toSt ringAsFixed(8)); | 44 // Expect.equals("-1.1111111111111111e+21", (-1111111111111111111111.0).toSt ringAsFixed(8)); |
antonm
2011/12/12 13:23:59
may you now uncomment those FIXMEs, there are I be
floitsch
2011/12/13 16:49:02
Done.
| |
45 Expect.equals("-0.1", (-0.1).toStringAsFixed(1)); | 45 Expect.equals("-0.1", (-0.1).toStringAsFixed(1)); |
46 Expect.equals("-0.10", (-0.1).toStringAsFixed(2)); | 46 Expect.equals("-0.10", (-0.1).toStringAsFixed(2)); |
47 Expect.equals("-0.100", (-0.1).toStringAsFixed(3)); | 47 Expect.equals("-0.100", (-0.1).toStringAsFixed(3)); |
48 Expect.equals("-0.01", (-0.01).toStringAsFixed(2)); | 48 Expect.equals("-0.01", (-0.01).toStringAsFixed(2)); |
49 Expect.equals("-0.010", (-0.01).toStringAsFixed(3)); | 49 Expect.equals("-0.010", (-0.01).toStringAsFixed(3)); |
50 Expect.equals("-0.0100", (-0.01).toStringAsFixed(4)); | 50 Expect.equals("-0.0100", (-0.01).toStringAsFixed(4)); |
51 Expect.equals("-0.00", (-0.001).toStringAsFixed(2)); | 51 Expect.equals("-0.00", (-0.001).toStringAsFixed(2)); |
52 Expect.equals("-0.001", (-0.001).toStringAsFixed(3)); | 52 Expect.equals("-0.001", (-0.001).toStringAsFixed(3)); |
53 Expect.equals("-0.0010", (-0.001).toStringAsFixed(4)); | 53 Expect.equals("-0.0010", (-0.001).toStringAsFixed(4)); |
54 Expect.equals("-1.0000", (-1.0).toStringAsFixed(4)); | 54 Expect.equals("-1.0000", (-1.0).toStringAsFixed(4)); |
55 Expect.equals("-1.0", (-1.0).toStringAsFixed(1)); | 55 Expect.equals("-1.0", (-1.0).toStringAsFixed(1)); |
56 Expect.equals("-1", (-1.0).toStringAsFixed(0)); | 56 Expect.equals("-1", (-1.0).toStringAsFixed(0)); |
57 Expect.equals("-1", (-1.1).toStringAsFixed(0)); | 57 Expect.equals("-1", (-1.1).toStringAsFixed(0)); |
58 Expect.equals("-12", (-12.1).toStringAsFixed(0)); | 58 Expect.equals("-12", (-12.1).toStringAsFixed(0)); |
59 Expect.equals("-1", (-1.12).toStringAsFixed(0)); | 59 Expect.equals("-1", (-1.12).toStringAsFixed(0)); |
60 Expect.equals("-12", (-12.12).toStringAsFixed(0)); | 60 Expect.equals("-12", (-12.12).toStringAsFixed(0)); |
61 Expect.equals("-0.0000006", (-0.0000006).toStringAsFixed(7)); | 61 Expect.equals("-0.0000006", (-0.0000006).toStringAsFixed(7)); |
62 Expect.equals("-0.00000006", (-0.00000006).toStringAsFixed(8)); | 62 Expect.equals("-0.00000006", (-0.00000006).toStringAsFixed(8)); |
63 Expect.equals("-0.000000060", (-0.00000006).toStringAsFixed(9)); | 63 Expect.equals("-0.000000060", (-0.00000006).toStringAsFixed(9)); |
64 Expect.equals("-0.0000000600", (-0.00000006).toStringAsFixed(10)); | 64 Expect.equals("-0.0000000600", (-0.00000006).toStringAsFixed(10)); |
65 Expect.equals("0", (-0.0).toStringAsFixed(0)); | 65 Expect.equals("-0", (-0.0).toStringAsFixed(0)); |
antonm
2011/12/12 13:23:59
just FYI: those expectations were taken from v8 te
floitsch
2011/12/13 16:49:02
This change is on purpose. Afaik there is no good
antonm
2011/12/14 06:44:44
It's up to you. For v8 we're bug-to-bug compatibl
floitsch
2011/12/14 09:23:49
We should be able to intercept the toString case o
| |
66 Expect.equals("0.0", (-0.0).toStringAsFixed(1)); | 66 Expect.equals("-0.0", (-0.0).toStringAsFixed(1)); |
67 Expect.equals("0.00", (-0.0).toStringAsFixed(2)); | 67 Expect.equals("-0.00", (-0.0).toStringAsFixed(2)); |
68 | 68 |
69 Expect.equals("1000", 1000.0.toStringAsFixed(0)); | 69 Expect.equals("1000", 1000.0.toStringAsFixed(0)); |
70 Expect.equals("0", 0.00001.toStringAsFixed(0)); | 70 Expect.equals("0", 0.00001.toStringAsFixed(0)); |
71 Expect.equals("0.00001", 0.00001.toStringAsFixed(5)); | 71 Expect.equals("0.00001", 0.00001.toStringAsFixed(5)); |
72 Expect.equals("0.00000000000000000010", 0.0000000000000000001.toStringAsFixe d(20)); | 72 Expect.equals("0.00000000000000000010", 0.0000000000000000001.toStringAsFixe d(20)); |
73 Expect.equals("0.00001000000000000", 0.00001.toStringAsFixed(17)); | 73 Expect.equals("0.00001000000000000", 0.00001.toStringAsFixed(17)); |
74 Expect.equals("1.00000000000000000", 1.0.toStringAsFixed(17)); | 74 Expect.equals("1.00000000000000000", 1.0.toStringAsFixed(17)); |
75 Expect.equals("1000000000000000128", 1000000000000000128.0.toStringAsFixed(0 )); | 75 Expect.equals("1000000000000000128", 1000000000000000128.0.toStringAsFixed(0 )); |
76 Expect.equals("100000000000000128.0", 100000000000000128.0.toStringAsFixed(1 )); | 76 Expect.equals("100000000000000128.0", 100000000000000128.0.toStringAsFixed(1 )); |
77 Expect.equals("10000000000000128.00", 10000000000000128.0.toStringAsFixed(2) ); | 77 Expect.equals("10000000000000128.00", 10000000000000128.0.toStringAsFixed(2) ); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 } | 110 } |
111 Expect.equals(true, thrown); | 111 Expect.equals(true, thrown); |
112 } | 112 } |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 main() { | 117 main() { |
118 ToStringAsFixedTest.testMain(); | 118 ToStringAsFixedTest.testMain(); |
119 } | 119 } |
OLD | NEW |