<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<script>
    description("Test the conversion performed by the function Number.prototype.toString.");

    var numberIndex = 0;
    var base10StringIndex = 1;
    var base2StringIndex = 2;
    var base36StringIndex = 3;

    var validNumberData = [
    // Regular Integers:
    [0, '0', '0', '0'],
    [-1, '-1', '-1', '-1'],
    [1, '1', '1', '1'],
    [1984, '1984', '11111000000', '1j4'],
    [-1984, '-1984', '-11111000000', '-1j4'],
    // Limits:
    [2147483647, '2147483647', '1111111111111111111111111111111', 'zik0zj'], // INT_MAX.
    [-2147483648, '-2147483648', '-10000000000000000000000000000000', '-zik0zk'], // INT_MIN
    [9007199254740992, '9007199254740992', '100000000000000000000000000000000000000000000000000000', '2gosa7pa2gw'], // Max Integer in a double.
    [-9007199254740992, '-9007199254740992', '-100000000000000000000000000000000000000000000000000000', '-2gosa7pa2gw'], // Min Integer in a double.

    // Integers represented as double.
    [0.0, '0', '0', '0'],
    [-1.0, '-1', '-1', '-1'],
    [1.0, '1', '1', '1'],
    [1984.0, '1984', '11111000000', '1j4'],
    [-1984.0, '-1984', '-11111000000', '-1j4'],
    // Limits:
    [2147483647.0, '2147483647', '1111111111111111111111111111111', 'zik0zj'], // INT_MAX.
    [-2147483648.0, '-2147483648', '-10000000000000000000000000000000', '-zik0zk'], // INT_MIN
    [9007199254740992.0, '9007199254740992', '100000000000000000000000000000000000000000000000000000', '2gosa7pa2gw'], // Max Integer in a double.
    [-9007199254740992.0, '-9007199254740992', '-100000000000000000000000000000000000000000000000000000', '-2gosa7pa2gw'], // Min Integer in a double.

    // Double.
    [0.1, '0.1', '0.0001100110011001100110011001100110011001100110011001101', '0.3lllllllllm'],
    [-1.1, '-1.1', '-1.000110011001100110011001100110011001100110011001101', '-1.3llllllllm'],
    [1.1, '1.1', '1.000110011001100110011001100110011001100110011001101', '1.3llllllllm'],
    [1984.1, '1984.1', '11111000000.00011001100110011001100110011001100110011', '1j4.3lllllllc'],
    [-1984.1, '-1984.1', '-11111000000.00011001100110011001100110011001100110011', '-1j4.3lllllllc'],
    // Limits:
    [2147483647.1, '2147483647.1', '1111111111111111111111111111111.000110011001100110011', 'zik0zj.3lllg'],
    [-2147483648.1, '-2147483648.1', '-10000000000000000000000000000000.000110011001100110011', '-zik0zk.3lllg'],
    [9007199254740992.1, '9007199254740992', '100000000000000000000000000000000000000000000000000000', '2gosa7pa2gw'],
    [-9007199254740992.1, '-9007199254740992', '-100000000000000000000000000000000000000000000000000000', '-2gosa7pa2gw'],
    ];

    for (var i = 0; i < validNumberData.length; ++i) {
        number = validNumberData[i][numberIndex];

        // Base 10:
        stringBase10 = validNumberData[i][base10StringIndex];
        shouldBeEqualToString('Number(' + number + ').toString()', stringBase10);
        shouldBeEqualToString('Number.prototype.toString.call(' + number + ')', stringBase10);
        shouldBeEqualToString('Number.prototype.toString.call(new Number(' + number + '))', stringBase10);
        // Passing the string to number should also lead to valid conversion.
        shouldBeEqualToString('Number("' + number + '").toString()', stringBase10);
        // Passing the base explicitly.
        shouldBeEqualToString('Number(' + number + ').toString(10)', stringBase10);

        // Base 2:
        stringBase2 = validNumberData[i][base2StringIndex];
        shouldBeEqualToString('Number(' + number + ').toString(2)', stringBase2);
        shouldBeEqualToString('Number.prototype.toString.call(' + number + ', 2)', stringBase2);
        shouldBeEqualToString('Number.prototype.toString.call(new Number(' + number + '), 2)', stringBase2);

        // Base 36:
        stringBase36 = validNumberData[i][base36StringIndex];
        shouldBeEqualToString('Number(' + number + ').toString(36)', stringBase36);
        shouldBeEqualToString('Number.prototype.toString.call(' + number + ', 36)', stringBase36);
        shouldBeEqualToString('Number.prototype.toString.call(new Number(' + number + '), 36)', stringBase36);
    }
    successfullyParsed = true;
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
