|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 */ |
|
5 |
|
6 function testInt(n, result) { |
|
7 var x = 0; |
|
8 for (var i = 0; i < 15; i++) { |
|
9 assertEq(parseInt(n, 10), result); |
|
10 assertEq(parseInt(n, 0), result); |
|
11 assertEq(parseInt(n), result); |
|
12 assertEq(parseInt(n, x), result); |
|
13 |
|
14 if (x % 2 == 0) |
|
15 x = 10; |
|
16 else |
|
17 x = 0; |
|
18 } |
|
19 } |
|
20 |
|
21 function testDouble(n, result) { |
|
22 var x = 0; |
|
23 for (var i = 0; i < 15; i++) { |
|
24 assertEq(parseInt(n, 10), result); |
|
25 assertEq(parseInt(n, 0), result); |
|
26 assertEq(parseInt(n), result); |
|
27 assertEq(parseInt(n, x), result); |
|
28 |
|
29 if (x % 2 == 0) |
|
30 x = 10; |
|
31 else |
|
32 x = 0; |
|
33 } |
|
34 } |
|
35 |
|
36 testInt(2147483647, 2147483647); |
|
37 testInt(-2147483648, -2147483648); |
|
38 testInt(17, 17); |
|
39 testInt(-1, -1); |
|
40 testInt(0, 0); |
|
41 |
|
42 testDouble(1e21, 1); |
|
43 testDouble(-5.7, -5); |
|
44 testDouble(1.7, 1); |
|
45 testDouble(1.0e-6, 0); |
|
46 testDouble(1.0e-7, 1); |
|
47 testDouble(NaN, NaN); |
|
48 testDouble(1e20, 1e20); |