• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.6.js
24    ECMA Section:       15.8.2.6  Math.ceil(x)
25    Description:        return the smallest number value that is not less than the
26                        argument and is equal to a mathematical integer.  if the
27                        number is already an integer, return the number itself.
28                        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.ceil(x) == -Math.ceil(-x)
37    Author:             christine@netscape.com
38    Date:               7 july 1997
39*/
40    var SECTION = "15.8.2.6";
41    var VERSION = "ECMA_1";
42    startTest();
43    var TITLE   = "Math.ceil(x)";
44
45    writeHeaderToLog( SECTION + " "+ TITLE);
46
47    var testcases = getTestCases();
48    test();
49
50function getTestCases() {
51    var array = new Array();
52    var item = 0;
53
54    array[item++] = new TestCase( SECTION, "Math.ceil.length",      1,              Math.ceil.length );
55
56    array[item++] = new TestCase( SECTION, "Math.ceil(NaN)",         Number.NaN,     Math.ceil(Number.NaN)   );
57    array[item++] = new TestCase( SECTION, "Math.ceil(null)",        0,              Math.ceil(null) );
58    array[item++] = new TestCase( SECTION, "Math.ceil()",            Number.NaN,     Math.ceil() );
59    array[item++] = new TestCase( SECTION, "Math.ceil(void 0)",      Number.NaN,     Math.ceil(void 0) );
60
61    array[item++] = new TestCase( SECTION, "Math.ceil('0')",            0,          Math.ceil('0')            );
62    array[item++] = new TestCase( SECTION, "Math.ceil('-0')",           -0,         Math.ceil('-0')           );
63    array[item++] = new TestCase( SECTION, "Infinity/Math.ceil('0')",   Infinity,   Infinity/Math.ceil('0'));
64    array[item++] = new TestCase( SECTION, "Infinity/Math.ceil('-0')",  -Infinity,  Infinity/Math.ceil('-0'));
65
66    array[item++] = new TestCase( SECTION, "Math.ceil(0)",           0,              Math.ceil(0)            );
67    array[item++] = new TestCase( SECTION, "Math.ceil(-0)",          -0,             Math.ceil(-0)           );
68    array[item++] = new TestCase( SECTION, "Infinity/Math.ceil(0)",     Infinity,   Infinity/Math.ceil(0));
69    array[item++] = new TestCase( SECTION, "Infinity/Math.ceil(-0)",    -Infinity,  Infinity/Math.ceil(-0));
70
71    array[item++] = new TestCase( SECTION, "Math.ceil(Infinity)",    Number.POSITIVE_INFINITY,   Math.ceil(Number.POSITIVE_INFINITY) );
72    array[item++] = new TestCase( SECTION, "Math.ceil(-Infinity)",   Number.NEGATIVE_INFINITY,   Math.ceil(Number.NEGATIVE_INFINITY) );
73    array[item++] = new TestCase( SECTION, "Math.ceil(-Number.MIN_VALUE)",   -0,     Math.ceil(-Number.MIN_VALUE) );
74    array[item++] = new TestCase( SECTION, "Infinity/Math.ceil(-Number.MIN_VALUE)",   -Infinity,     Infinity/Math.ceil(-Number.MIN_VALUE) );
75    array[item++] = new TestCase( SECTION, "Math.ceil(1)",          1,              Math.ceil(1)   );
76    array[item++] = new TestCase( SECTION, "Math.ceil(-1)",          -1,            Math.ceil(-1)   );
77    array[item++] = new TestCase( SECTION, "Math.ceil(-0.9)",        -0,            Math.ceil(-0.9) );
78    array[item++] = new TestCase( SECTION, "Infinity/Math.ceil(-0.9)",  -Infinity,  Infinity/Math.ceil(-0.9) );
79    array[item++] = new TestCase( SECTION, "Math.ceil(0.9 )",        1,             Math.ceil( 0.9) );
80    array[item++] = new TestCase( SECTION, "Math.ceil(-1.1)",        -1,            Math.ceil( -1.1));
81    array[item++] = new TestCase( SECTION, "Math.ceil( 1.1)",        2,             Math.ceil(  1.1));
82
83    array[item++] = new TestCase( SECTION, "Math.ceil(Infinity)",   -Math.floor(-Infinity),    Math.ceil(Number.POSITIVE_INFINITY) );
84    array[item++] = new TestCase( SECTION, "Math.ceil(-Infinity)",  -Math.floor(Infinity),     Math.ceil(Number.NEGATIVE_INFINITY) );
85    array[item++] = new TestCase( SECTION, "Math.ceil(-Number.MIN_VALUE)",   -Math.floor(Number.MIN_VALUE),     Math.ceil(-Number.MIN_VALUE) );
86    array[item++] = new TestCase( SECTION, "Math.ceil(1)",          -Math.floor(-1),        Math.ceil(1)   );
87    array[item++] = new TestCase( SECTION, "Math.ceil(-1)",         -Math.floor(1),         Math.ceil(-1)   );
88    array[item++] = new TestCase( SECTION, "Math.ceil(-0.9)",       -Math.floor(0.9),       Math.ceil(-0.9) );
89    array[item++] = new TestCase( SECTION, "Math.ceil(0.9 )",       -Math.floor(-0.9),      Math.ceil( 0.9) );
90    array[item++] = new TestCase( SECTION, "Math.ceil(-1.1)",       -Math.floor(1.1),       Math.ceil( -1.1));
91    array[item++] = new TestCase( SECTION, "Math.ceil( 1.1)",       -Math.floor(-1.1),      Math.ceil(  1.1));
92
93    return ( array );
94}
95
96function test() {
97    for ( tc=0; tc < testcases.length; tc++ ) {
98        testcases[tc].passed = writeTestCaseResult(
99                            testcases[tc].expect,
100                            testcases[tc].actual,
101                            testcases[tc].description +" = "+
102                            testcases[tc].actual );
103
104        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
105    }
106    stopTest();
107    return ( testcases );
108}
109