]>
Commit | Line | Data |
---|---|---|
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: 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 | |
30 | - if x = +0 return +0 | |
31 | - if x = -0 return -0 | |
32 | - if x = Infinity return Infinity | |
33 | - if x = -Infinity return -Infinity | |
34 | - if ( -1 < x < 0 ) return -0 | |
35 | also: | |
36 | - the value of Math.floor(x) == -Math.ceil(-x) | |
37 | Author: christine@netscape.com | |
38 | Date: 7 july 1997 | |
39 | */ | |
40 | ||
41 | var SECTION = "15.8.2.9"; | |
42 | var VERSION = "ECMA_1"; | |
43 | startTest(); | |
44 | var TITLE = "Math.floor(x)"; | |
45 | ||
46 | writeHeaderToLog( SECTION + " "+ TITLE); | |
47 | ||
48 | var testcases = getTestCases(); | |
49 | test(); | |
50 | ||
51 | function getTestCases() { | |
52 | var array = new Array(); | |
53 | var item = 0; | |
54 | ||
55 | array[item++] = new TestCase( SECTION, "Math.floor.length", 1, Math.floor.length ); | |
56 | ||
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) ); | |
62 | ||
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") ); | |
67 | ||
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) ); | |
70 | ||
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) ); | |
73 | ||
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) ); | |
77 | ||
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) ); | |
80 | ||
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) ); | |
83 | ||
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) ); | |
86 | ||
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) ); | |
89 | ||
90 | return ( array ); | |
91 | } | |
92 | ||
93 | function test() { | |
94 | for ( tc=0; tc < testcases.length; tc++ ) { | |
95 | testcases[tc].passed = writeTestCaseResult( | |
96 | testcases[tc].expect, | |
97 | testcases[tc].actual, | |
98 | testcases[tc].description +" = "+ | |
99 | testcases[tc].actual ); | |
100 | ||
101 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
102 | } | |
103 | stopTest(); | |
104 | return ( testcases ); | |
105 | } |