michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: function testInt(n, result) { michael@0: var x = 0; michael@0: for (var i = 0; i < 15; i++) { michael@0: assertEq(parseInt(n, 10), result); michael@0: assertEq(parseInt(n, 0), result); michael@0: assertEq(parseInt(n), result); michael@0: assertEq(parseInt(n, x), result); michael@0: michael@0: if (x % 2 == 0) michael@0: x = 10; michael@0: else michael@0: x = 0; michael@0: } michael@0: } michael@0: michael@0: function testDouble(n, result) { michael@0: var x = 0; michael@0: for (var i = 0; i < 15; i++) { michael@0: assertEq(parseInt(n, 10), result); michael@0: assertEq(parseInt(n, 0), result); michael@0: assertEq(parseInt(n), result); michael@0: assertEq(parseInt(n, x), result); michael@0: michael@0: if (x % 2 == 0) michael@0: x = 10; michael@0: else michael@0: x = 0; michael@0: } michael@0: } michael@0: michael@0: testInt(2147483647, 2147483647); michael@0: testInt(-2147483648, -2147483648); michael@0: testInt(17, 17); michael@0: testInt(-1, -1); michael@0: testInt(0, 0); michael@0: michael@0: testDouble(1e21, 1); michael@0: testDouble(-5.7, -5); michael@0: testDouble(1.7, 1); michael@0: testDouble(1.0e-6, 0); michael@0: testDouble(1.0e-7, 1); michael@0: testDouble(NaN, NaN); michael@0: testDouble(1e20, 1e20);