]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Math/15.8.2.15.js
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.15.js
24 ECMA Section: 15.8.2.15 Math.round(x)
25 Description: return the greatest number value that is closest to the
26 argument and is an integer. if two integers are equally
27 close to the argument. then the result is the number value
28 that is closer to Infinity. if the argument is an integer,
31 - if x is NaN return NaN
34 - if x = Infinity return Infinity
35 - if x = -Infinity return -Infinity
36 - if 0 < x < 0.5 return 0
37 - if -0.5 <= x < 0 return -0
39 Math.round( 3.5 ) == 4
40 Math.round( -3.5 ) == 3
42 - Math.round(x) == Math.floor( x + 0.5 )
43 except if x = -0. in that case, Math.round(x) = -0
45 and Math.floor( x+0.5 ) = +0
48 Author: christine@netscape.com
52 var SECTION
= "15.8.2.15";
53 var VERSION
= "ECMA_1";
55 var TITLE
= "Math.round(x)";
56 var BUGNUMBER
="331411";
60 writeHeaderToLog( SECTION
+ " "+ TITLE
);
62 var testcases
= getTestCases();
65 function getTestCases() {
66 var array
= new Array();
69 array
[item
++] = new TestCase( SECTION
, "Math.round.length", 1, Math
.round
.length
);
71 array
[item
++] = new TestCase( SECTION
, "Math.round()", Number
.NaN
, Math
.round() );
72 array
[item
++] = new TestCase( SECTION
, "Math.round(null)", 0, Math
.round(0) );
73 array
[item
++] = new TestCase( SECTION
, "Math.round(void 0)", Number
.NaN
, Math
.round(void 0) );
74 array
[item
++] = new TestCase( SECTION
, "Math.round(true)", 1, Math
.round(true) );
75 array
[item
++] = new TestCase( SECTION
, "Math.round(false)", 0, Math
.round(false) );
76 array
[item
++] = new TestCase( SECTION
, "Math.round('.99999')", 1, Math
.round('.99999') );
77 array
[item
++] = new TestCase( SECTION
, "Math.round('12345e-2')", 123, Math
.round('12345e-2') );
79 array
[item
++] = new TestCase( SECTION
, "Math.round(NaN)", Number
.NaN
, Math
.round(Number
.NaN
) );
80 array
[item
++] = new TestCase( SECTION
, "Math.round(0)", 0, Math
.round(0) );
81 array
[item
++] = new TestCase( SECTION
, "Math.round(-0)", -0, Math
.round(-0));
82 array
[item
++] = new TestCase( SECTION
, "Infinity/Math.round(-0)", -Infinity
, Infinity
/Math
.round(-0) );
84 array
[item
++] = new TestCase( SECTION
, "Math.round(Infinity)", Number
.POSITIVE_INFINITY
, Math
.round(Number
.POSITIVE_INFINITY
));
85 array
[item
++] = new TestCase( SECTION
, "Math.round(-Infinity)",Number
.NEGATIVE_INFINITY
, Math
.round(Number
.NEGATIVE_INFINITY
));
86 array
[item
++] = new TestCase( SECTION
, "Math.round(0.49)", 0, Math
.round(0.49));
87 array
[item
++] = new TestCase( SECTION
, "Math.round(0.5)", 1, Math
.round(0.5));
88 array
[item
++] = new TestCase( SECTION
, "Math.round(0.51)", 1, Math
.round(0.51));
90 array
[item
++] = new TestCase( SECTION
, "Math.round(-0.49)", -0, Math
.round(-0.49));
91 array
[item
++] = new TestCase( SECTION
, "Math.round(-0.5)", -0, Math
.round(-0.5));
92 array
[item
++] = new TestCase( SECTION
, "Infinity/Math.round(-0.49)", -Infinity
, Infinity
/Math
.round(-0.49));
93 array
[item
++] = new TestCase( SECTION
, "Infinity/Math.round(-0.5)", -Infinity
, Infinity
/Math
.round(-0.5));
95 array
[item
++] = new TestCase( SECTION
, "Math.round(-0.51)", -1, Math
.round(-0.51));
96 array
[item
++] = new TestCase( SECTION
, "Math.round(3.5)", 4, Math
.round(3.5));
97 array
[item
++] = new TestCase( SECTION
, "Math.round(-3.5)", -3, Math
.round(-3));
102 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
103 testcases
[tc
].passed
= writeTestCaseResult(
104 testcases
[tc
].expect
,
105 testcases
[tc
].actual
,
106 testcases
[tc
].description
+" = "+
107 testcases
[tc
].actual
);
109 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
112 return ( testcases
);