1/* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
5 *
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23    File Name:          9.3-1.js
24    ECMA Section:       9.3  Type Conversion:  ToNumber
25    Description:        rules for converting an argument to a number.
26                        see 9.3.1 for cases for converting strings to numbers.
27                        special cases:
28                        undefined           NaN
29                        Null                NaN
30                        Boolean             1 if true; +0 if false
31                        Number              the argument ( no conversion )
32                        String              see test 9.3.1
33                        Object              see test 9.3-1
34
35
36                        This tests ToNumber applied to the object type, except
37                        if object is string.  See 9.3-2 for
38                        ToNumber( String object).
39
40    Author:             christine@netscape.com
41    Date:               10 july 1997
42
43*/
44    var SECTION = "9.3-1";
45    var VERSION = "ECMA_1";
46    startTest();
47    var TYPE = "number";
48    var testcases = getTestCases();
49
50    writeHeaderToLog( SECTION + " ToNumber");
51    test();
52
53function test() {
54    for ( tc=0; tc < testcases.length; tc++ ) {
55        testcases[tc].passed = writeTestCaseResult(
56                            testcases[tc].expect,
57                            testcases[tc].actual,
58                            testcases[tc].description +" = "+
59                            testcases[tc].actual );
60
61                    testcases[tc].passed = writeTestCaseResult(
62                                TYPE,
63                                typeof(testcases[tc].actual),
64                                "typeof( " + testcases[tc].description +
65                                " ) = " + typeof(testcases[tc].actual) )
66                                ? testcases[tc].passed
67                                : false;
68
69        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
70    }
71    stopTest();
72    return ( testcases );
73}
74function getTestCases() {
75    var array = new Array();
76    var item = 0;
77
78    // object is Number
79    array[item++] = new TestCase( SECTION,   "Number(new Number())",          0,              Number(new Number())  );
80    array[item++] = new TestCase( SECTION,   "Number(new Number(Number.NaN))",Number.NaN,     Number(new Number(Number.NaN)) );
81    array[item++] = new TestCase( SECTION,   "Number(new Number(0))",         0,              Number(new Number(0)) );
82    array[item++] = new TestCase( SECTION,   "Number(new Number(null))",      0,              Number(new Number(null)) );
83//    array[item++] = new TestCase( SECTION,   "Number(new Number(void 0))",    Number.NaN,     Number(new Number(void 0)) );
84    array[item++] = new TestCase( SECTION,   "Number(new Number(true))",      1,              Number(new Number(true)) );
85    array[item++] = new TestCase( SECTION,   "Number(new Number(false))",     0,              Number(new Number(false)) );
86
87    // object is boolean
88
89    array[item++] = new TestCase( SECTION,   "Number(new Boolean(true))",     1,  Number(new Boolean(true)) );
90    array[item++] = new TestCase( SECTION,   "Number(new Boolean(false))",    0,  Number(new Boolean(false)) );
91
92    // object is array
93    array[item++] = new TestCase( SECTION,   "Number(new Array(2,4,8,16,32))",      Number.NaN,     Number(new Array(2,4,8,16,32)) );
94
95    return ( array );
96}
97