]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Math/15.8.2.9.js
c1ea987edacad2c92c06843264780805c317c982
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
23 File Name: 15.8.2.9.js
24 ECMA Section: 15.8.2.9 Math.floor(x)
25 Description: return the greatest number value that is not greater
26 than the argument and is equal to a mathematical integer.
27 if the number is already an integer, return the number
28 itself. special cases:
29 - if x is NaN return NaN
32 - if x = Infinity return Infinity
33 - if x = -Infinity return -Infinity
34 - if ( -1 < x < 0 ) return -0
36 - the value of Math.floor(x) == -Math.ceil(-x)
37 Author: christine@netscape.com
41 var SECTION
= "15.8.2.9";
42 var VERSION
= "ECMA_1";
44 var TITLE
= "Math.floor(x)";
46 writeHeaderToLog( SECTION
+ " "+ TITLE
);
48 var testcases
= getTestCases();
51 function getTestCases() {
52 var array
= new Array();
55 array
[item
++] = new TestCase( SECTION
, "Math.floor.length", 1, Math
.floor
.length
);
57 array
[item
++] = new TestCase( SECTION
, "Math.floor()", Number
.NaN
, Math
.floor() );
58 array
[item
++] = new TestCase( SECTION
, "Math.floor(void 0)", Number
.NaN
, Math
.floor(void 0) );
59 array
[item
++] = new TestCase( SECTION
, "Math.floor(null)", 0, Math
.floor(null) );
60 array
[item
++] = new TestCase( SECTION
, "Math.floor(true)", 1, Math
.floor(true) );
61 array
[item
++] = new TestCase( SECTION
, "Math.floor(false)", 0, Math
.floor(false) );
63 array
[item
++] = new TestCase( SECTION
, "Math.floor('1.1')", 1, Math
.floor("1.1") );
64 array
[item
++] = new TestCase( SECTION
, "Math.floor('-1.1')", -2, Math
.floor("-1.1") );
65 array
[item
++] = new TestCase( SECTION
, "Math.floor('0.1')", 0, Math
.floor("0.1") );
66 array
[item
++] = new TestCase( SECTION
, "Math.floor('-0.1')", -1, Math
.floor("-0.1") );
68 array
[item
++] = new TestCase( SECTION
, "Math.floor(NaN)", Number
.NaN
, Math
.floor(Number
.NaN
) );
69 array
[item
++] = new TestCase( SECTION
, "Math.floor(NaN)==-Math.ceil(-NaN)", false, Math
.floor(Number
.NaN
) == -Math
.ceil(-Number
.NaN
) );
71 array
[item
++] = new TestCase( SECTION
, "Math.floor(0)", 0, Math
.floor(0) );
72 array
[item
++] = new TestCase( SECTION
, "Math.floor(0)==-Math.ceil(-0)", true, Math
.floor(0) == -Math
.ceil(-0) );
74 array
[item
++] = new TestCase( SECTION
, "Math.floor(-0)", -0, Math
.floor(-0) );
75 array
[item
++] = new TestCase( SECTION
, "Infinity/Math.floor(-0)", -Infinity
, Infinity
/Math
.floor(-0) );
76 array
[item
++] = new TestCase( SECTION
, "Math.floor(-0)==-Math.ceil(0)", true, Math
.floor(-0)== -Math
.ceil(0) );
78 array
[item
++] = new TestCase( SECTION
, "Math.floor(Infinity)", Number
.POSITIVE_INFINITY
, Math
.floor(Number
.POSITIVE_INFINITY
) );
79 array
[item
++] = new TestCase( SECTION
, "Math.floor(Infinity)==-Math.ceil(-Infinity)", true, Math
.floor(Number
.POSITIVE_INFINITY
) == -Math
.ceil(Number
.NEGATIVE_INFINITY
) );
81 array
[item
++] = new TestCase( SECTION
, "Math.floor(-Infinity)", Number
.NEGATIVE_INFINITY
, Math
.floor(Number
.NEGATIVE_INFINITY
) );
82 array
[item
++] = new TestCase( SECTION
, "Math.floor(-Infinity)==-Math.ceil(Infinity)", true, Math
.floor(Number
.NEGATIVE_INFINITY
) == -Math
.ceil(Number
.POSITIVE_INFINITY
) );
84 array
[item
++] = new TestCase( SECTION
, "Math.floor(0.0000001)", 0, Math
.floor(0.0000001) );
85 array
[item
++] = new TestCase( SECTION
, "Math.floor(0.0000001)==-Math.ceil(0.0000001)", true, Math
.floor(0.0000001)==-Math
.ceil(-0.0000001) );
87 array
[item
++] = new TestCase( SECTION
, "Math.floor(-0.0000001)", -1, Math
.floor(-0.0000001) );
88 array
[item
++] = new TestCase( SECTION
, "Math.floor(0.0000001)==-Math.ceil(0.0000001)", true, Math
.floor(-0.0000001)==-Math
.ceil(0.0000001) );
94 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
95 testcases
[tc
].passed
= writeTestCaseResult(
98 testcases
[tc
].description
+" = "+
99 testcases
[tc
].actual
);
101 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
104 return ( testcases
);