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/
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.
11 * The Original Code is Mozilla Communicator client code, released March
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
24 ECMA Section: 9.4 ToInteger
25 Description: 1. Call ToNumber on the input argument
26 2. If Result(1) is NaN, return +0
27 3. If Result(1) is +0, -0, Infinity, or -Infinity,
29 4. Compute sign(Result(1)) * floor(abs(Result(1))).
32 To test ToInteger, this test uses new Date(value),
33 15.9.3.7. The Date constructor sets the [[Value]]
34 property of the new object to TimeClip(value), which
38 1. If time is not finite, return NaN
39 2. If abs(Result(1)) > 8.64e15, return NaN
40 3. Return an implementation dependent choice of either
41 ToInteger(Result(2)) or ToInteger(Result(2)) + (+0)
42 (Adding a positive 0 converts -0 to +0).
44 This tests ToInteger for values -8.64e15 > value > 8.64e15,
45 not including -0 and +0.
47 For additional special cases (0, +0, Infinity, -Infinity,
48 and NaN, see 9.4-2.js). For value is String, see 9.4-3.js.
50 Author: christine@netscape.com
54 var SECTION = "9.4-1";
55 var VERSION = "ECMA_1";
57 var TITLE = "ToInteger";
59 writeHeaderToLog( SECTION + " "+ TITLE);
61 var testcases = getTestCases();
65 for ( tc=0; tc < testcases.length; tc++ ) {
66 testcases[tc].passed = writeTestCaseResult(
69 testcases[tc].description +" = "+
70 testcases[tc].actual );
73 testcases[tc].passed = writeTestCaseResult(
76 testcases[tc].description +" = "+ testcases[tc].actual );
78 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
83 function getTestCases() {
84 var array = new Array();
89 array[item++] = new TestCase( SECTION, "td = new Date(Number.NaN); td.valueOf()", Number.NaN, eval("td = new Date(Number.NaN); td.valueOf()") );
90 array[item++] = new TestCase( SECTION, "td = new Date(Infinity); td.valueOf()", Number.NaN, eval("td = new Date(Number.POSITIVE_INFINITY); td.valueOf()") );
91 array[item++] = new TestCase( SECTION, "td = new Date(-Infinity); td.valueOf()", Number.NaN, eval("td = new Date(Number.NEGATIVE_INFINITY); td.valueOf()") );
92 array[item++] = new TestCase( SECTION, "td = new Date(-0); td.valueOf()", -0, eval("td = new Date(-0); td.valueOf()" ) );
93 array[item++] = new TestCase( SECTION, "td = new Date(0); td.valueOf()", 0, eval("td = new Date(0); td.valueOf()") );
95 // value is not an integer
97 array[item++] = new TestCase( SECTION, "td = new Date(3.14159); td.valueOf()", 3, eval("td = new Date(3.14159); td.valueOf()") );
98 array[item++] = new TestCase( SECTION, "td = new Date(Math.PI); td.valueOf()", 3, eval("td = new Date(Math.PI); td.valueOf()") );
99 array[item++] = new TestCase( SECTION, "td = new Date(-Math.PI);td.valueOf()", -3, eval("td = new Date(-Math.PI);td.valueOf()") );
100 array[item++] = new TestCase( SECTION, "td = new Date(3.14159e2); td.valueOf()", 314, eval("td = new Date(3.14159e2); td.valueOf()") );
102 array[item++] = new TestCase( SECTION, "td = new Date(.692147e1); td.valueOf()", 6, eval("td = new Date(.692147e1);td.valueOf()") );
103 array[item++] = new TestCase( SECTION, "td = new Date(-.692147e1);td.valueOf()", -6, eval("td = new Date(-.692147e1);td.valueOf()") );
105 // value is not a number
107 array[item++] = new TestCase( SECTION, "td = new Date(true); td.valueOf()", 1, eval("td = new Date(true); td.valueOf()" ) );
108 array[item++] = new TestCase( SECTION, "td = new Date(false); td.valueOf()", 0, eval("td = new Date(false); td.valueOf()") );
110 array[item++] = new TestCase( SECTION, "td = new Date(new Number(Math.PI)); td.valueOf()", 3, eval("td = new Date(new Number(Math.PI)); td.valueOf()") );
111 array[item++] = new TestCase( SECTION, "td = new Date(new Number(Math.PI)); td.valueOf()", 3, eval("td = new Date(new Number(Math.PI)); td.valueOf()") );
114 array[item++] = new TestCase( SECTION, "td = new Date(8.64e15); td.valueOf()", 8.64e15, eval("td = new Date(8.64e15); td.valueOf()") );
115 array[item++] = new TestCase( SECTION, "td = new Date(-8.64e15); td.valueOf()", -8.64e15, eval("td = new Date(-8.64e15); td.valueOf()") );
116 array[item++] = new TestCase( SECTION, "td = new Date(8.64e-15); td.valueOf()", 0, eval("td = new Date(8.64e-15); td.valueOf()") );
117 array[item++] = new TestCase( SECTION, "td = new Date(-8.64e-15); td.valueOf()", 0, eval("td = new Date(-8.64e-15); td.valueOf()") );