js/src/tests/ecma/Math/15.8.2.1.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:ac76fa45b40e
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
7 /**
8 File Name: 15.8.2.1.js
9 ECMA Section: 15.8.2.1 abs( x )
10 Description: return the absolute value of the argument,
11 which should be the magnitude of the argument
12 with a positive sign.
13 - if x is NaN, return NaN
14 - if x is -0, result is +0
15 - if x is -Infinity, result is +Infinity
16 Author: christine@netscape.com
17 Date: 7 july 1997
18 */
19 var SECTION = "15.8.2.1";
20 var VERSION = "ECMA_1";
21 var TITLE = "Math.abs()";
22 var BUGNUMBER = "77391";
23 startTest();
24
25 writeHeaderToLog( SECTION + " "+ TITLE);
26
27 new TestCase( SECTION,
28 "Math.abs.length",
29 1,
30 Math.abs.length );
31
32 new TestCase( SECTION,
33 "Math.abs()",
34 Number.NaN,
35 Math.abs() );
36
37 new TestCase( SECTION,
38 "Math.abs( void 0 )",
39 Number.NaN,
40 Math.abs(void 0) );
41
42 new TestCase( SECTION,
43 "Math.abs( null )",
44 0,
45 Math.abs(null) );
46
47 new TestCase( SECTION,
48 "Math.abs( true )",
49 1,
50 Math.abs(true) );
51
52 new TestCase( SECTION,
53 "Math.abs( false )",
54 0,
55 Math.abs(false) );
56
57 new TestCase( SECTION,
58 "Math.abs( string primitive)",
59 Number.NaN,
60 Math.abs("a string primitive") );
61
62 new TestCase( SECTION,
63 "Math.abs( string object )",
64 Number.NaN,
65 Math.abs(new String( 'a String object' )) );
66
67 new TestCase( SECTION,
68 "Math.abs( Number.NaN )",
69 Number.NaN,
70 Math.abs(Number.NaN) );
71
72 new TestCase( SECTION,
73 "Math.abs(0)",
74 0,
75 Math.abs( 0 ) );
76
77 new TestCase( SECTION,
78 "Math.abs( -0 )",
79 0,
80 Math.abs(-0) );
81
82 new TestCase( SECTION,
83 "Infinity/Math.abs(-0)",
84 Infinity,
85 Infinity/Math.abs(-0) );
86
87 new TestCase( SECTION,
88 "Math.abs( -Infinity )",
89 Number.POSITIVE_INFINITY,
90 Math.abs( Number.NEGATIVE_INFINITY ) );
91
92 new TestCase( SECTION,
93 "Math.abs( Infinity )",
94 Number.POSITIVE_INFINITY,
95 Math.abs( Number.POSITIVE_INFINITY ) );
96
97 new TestCase( SECTION,
98 "Math.abs( - MAX_VALUE )",
99 Number.MAX_VALUE,
100 Math.abs( - Number.MAX_VALUE ) );
101
102 new TestCase( SECTION,
103 "Math.abs( - MIN_VALUE )",
104 Number.MIN_VALUE,
105 Math.abs( -Number.MIN_VALUE ) );
106
107 new TestCase( SECTION,
108 "Math.abs( MAX_VALUE )",
109 Number.MAX_VALUE,
110 Math.abs( Number.MAX_VALUE ) );
111
112 new TestCase( SECTION,
113 "Math.abs( MIN_VALUE )",
114 Number.MIN_VALUE,
115 Math.abs( Number.MIN_VALUE ) );
116
117 new TestCase( SECTION,
118 "Math.abs( -1 )",
119 1,
120 Math.abs( -1 ) );
121
122 new TestCase( SECTION,
123 "Math.abs( new Number( -1 ) )",
124 1,
125 Math.abs( new Number(-1) ) );
126
127 new TestCase( SECTION,
128 "Math.abs( 1 )",
129 1,
130 Math.abs( 1 ) );
131
132 new TestCase( SECTION,
133 "Math.abs( Math.PI )",
134 Math.PI,
135 Math.abs( Math.PI ) );
136
137 new TestCase( SECTION,
138 "Math.abs( -Math.PI )",
139 Math.PI,
140 Math.abs( -Math.PI ) );
141
142 new TestCase( SECTION,
143 "Math.abs(-1/100000000)",
144 1/100000000,
145 Math.abs(-1/100000000) );
146
147 new TestCase( SECTION,
148 "Math.abs(-Math.pow(2,32))",
149 Math.pow(2,32),
150 Math.abs(-Math.pow(2,32)) );
151
152 new TestCase( SECTION,
153 "Math.abs(Math.pow(2,32))",
154 Math.pow(2,32),
155 Math.abs(Math.pow(2,32)) );
156
157 new TestCase( SECTION,
158 "Math.abs( -0xfff )",
159 4095,
160 Math.abs( -0xfff ) );
161
162 new TestCase( SECTION,
163 "Math.abs( -0777 )",
164 511,
165 Math.abs(-0777 ) );
166
167 new TestCase( SECTION,
168 "Math.abs('-1e-1')",
169 0.1,
170 Math.abs('-1e-1') );
171
172 new TestCase( SECTION,
173 "Math.abs('0xff')",
174 255,
175 Math.abs('0xff') );
176
177 new TestCase( SECTION,
178 "Math.abs('077')",
179 77,
180 Math.abs('077') );
181
182 new TestCase( SECTION,
183 "Math.abs( 'Infinity' )",
184 Infinity,
185 Math.abs('Infinity') );
186
187 new TestCase( SECTION,
188 "Math.abs( '-Infinity' )",
189 Infinity,
190 Math.abs('-Infinity') );
191
192 test();

mercurial