Debian Codegraph @

rhino/testsrc/tests/ecma/Math/15.8.2.15.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '15.8.2.15.js';
7
8 /**
9 File Name: 15.8.2.15.js
10 ECMA Section: 15.8.2.15 Math.round(x)
11 Description: return the greatest number value that is closest to the
12 argument and is an integer. if two integers are equally
13 close to the argument. then the result is the number value
14 that is closer to Infinity. if the argument is an integer,
15 return the argument.
16 special cases:
17 - if x is NaN return NaN
18 - if x = +0 return +0
19 - if x = -0 return -0
20 - if x = Infinity return Infinity
21 - if x = -Infinity return -Infinity
22 - if 0 < x < 0.5 return 0
23 - if -0.5 <= x < 0 return -0
24 example:
25 Math.round( 3.5 ) == 4
26 Math.round( -3.5 ) == 3
27 also:
28 - Math.round(x) == Math.floor( x + 0.5 )
29 except if x = -0. in that case, Math.round(x) = -0
30
31 and Math.floor( x+0.5 ) = +0
32
33
34 Author: [email protected]
35 Date: 7 july 1997
36 */
37
38 var SECTION = "15.8.2.15";
39 var VERSION = "ECMA_1";
40 var TITLE = "Math.round(x)";
41 var BUGNUMBER="331411";
42
43 var EXCLUDE = "true";
44
45 startTest();
46
47 writeHeaderToLog( SECTION + " "+ TITLE);
48
49 new TestCase( SECTION,
50 "Math.round.length",
51 1,
52 Math.round.length );
53
54 new TestCase( SECTION,
55 "Math.round()",
56 Number.NaN,
57 Math.round() );
58
59 new TestCase( SECTION,
60 "Math.round(null)",
61 0,
62 Math.round(0) );
63
64 new TestCase( SECTION,
65 "Math.round(void 0)",
66 Number.NaN,
67 Math.round(void 0) );
68
69 new TestCase( SECTION,
70 "Math.round(true)",
71 1,
72 Math.round(true) );
73
74 new TestCase( SECTION,
75 "Math.round(false)",
76 0,
77 Math.round(false) );
78
79 new TestCase( SECTION,
80 "Math.round('.99999')",
81 1,
82 Math.round('.99999') );
83
84 new TestCase( SECTION,
85 "Math.round('12345e-2')",
86 123,
87 Math.round('12345e-2') );
88
89 new TestCase( SECTION,
90 "Math.round(NaN)",
91 Number.NaN,
92 Math.round(Number.NaN) );
93
94 new TestCase( SECTION,
95 "Math.round(0)",
96 0,
97 Math.round(0) );
98
99 new TestCase( SECTION,
100 "Math.round(-0)",
101 -0,
102 Math.round(-0));
103
104 new TestCase( SECTION,
105 "Infinity/Math.round(-0)",
106 -Infinity,
107 Infinity/Math.round(-0) );
108
109 new TestCase( SECTION,
110 "Math.round(Infinity)",
111 Number.POSITIVE_INFINITY,
112 Math.round(Number.POSITIVE_INFINITY));
113
114 new TestCase( SECTION,
115 "Math.round(-Infinity)",
116 Number.NEGATIVE_INFINITY,
117 Math.round(Number.NEGATIVE_INFINITY));
118
119 new TestCase( SECTION,
120 "Math.round(0.49)",
121 0,
122 Math.round(0.49));
123
124 new TestCase( SECTION,
125 "Math.round(0.5)",
126 1,
127 Math.round(0.5));
128
129 new TestCase( SECTION,
130 "Math.round(0.51)",
131 1,
132 Math.round(0.51));
133
134 new TestCase( SECTION,
135 "Math.round(-0.49)",
136 -0,
137 Math.round(-0.49));
138
139 new TestCase( SECTION,
140 "Math.round(-0.5)",
141 -0,
142 Math.round(-0.5));
143
144 new TestCase( SECTION,
145 "Infinity/Math.round(-0.49)",
146 -Infinity,
147 Infinity/Math.round(-0.49));
148
149 new TestCase( SECTION,
150 "Infinity/Math.round(-0.5)",
151 -Infinity,
152 Infinity/Math.round(-0.5));
153
154 new TestCase( SECTION,
155 "Math.round(-0.51)",
156 -1,
157 Math.round(-0.51));
158
159 new TestCase( SECTION,
160 "Math.round(3.5)",
161 4,
162 Math.round(3.5));
163
164 new TestCase( SECTION,
165 "Math.round(-3.5)",
166 -3,
167 Math.round(-3));
168
169 test();