]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Math/15.8.2.1.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.1.js
24 ECMA Section: 15.8.2.1 abs( x )
25 Description: return the absolute value of the argument,
26 which should be the magnitude of the argument
28 - if x is NaN, return NaN
29 - if x is -0, result is +0
30 - if x is -Infinity, result is +Infinity
31 Author: christine@netscape.com
34 var SECTION
= "15.8.2.1";
35 var VERSION
= "ECMA_1";
37 var TITLE
= "Math.abs()";
38 var BUGNUMBER
= "77391";
40 writeHeaderToLog( SECTION
+ " "+ TITLE
);
42 var testcases
= getTestCases();
45 function getTestCases() {
46 var array
= new Array();
49 array
[item
++] = new TestCase( SECTION
, "Math.abs.length", 1, Math
.abs
.length
);
51 array
[item
++] = new TestCase( SECTION
, "Math.abs()", Number
.NaN
, Math
.abs() );
52 array
[item
++] = new TestCase( SECTION
, "Math.abs( void 0 )", Number
.NaN
, Math
.abs(void 0) );
53 array
[item
++] = new TestCase( SECTION
, "Math.abs( null )", 0, Math
.abs(null) );
54 array
[item
++] = new TestCase( SECTION
, "Math.abs( true )", 1, Math
.abs(true) );
55 array
[item
++] = new TestCase( SECTION
, "Math.abs( false )", 0, Math
.abs(false) );
56 array
[item
++] = new TestCase( SECTION
, "Math.abs( string primitive)", Number
.NaN
, Math
.abs("a string primitive") );
57 array
[item
++] = new TestCase( SECTION
, "Math.abs( string object )", Number
.NaN
, Math
.abs(new String( 'a String object' )) );
58 array
[item
++] = new TestCase( SECTION
, "Math.abs( Number.NaN )", Number
.NaN
, Math
.abs(Number
.NaN
) );
60 array
[item
++] = new TestCase( SECTION
, "Math.abs(0)", 0, Math
.abs( 0 ) );
61 array
[item
++] = new TestCase( SECTION
, "Math.abs( -0 )", 0, Math
.abs(-0) );
62 array
[item
++] = new TestCase( SECTION
, "Infinity/Math.abs(-0)", Infinity
, Infinity
/Math
.abs(-0) );
64 array
[item
++] = new TestCase( SECTION
, "Math.abs( -Infinity )", Number
.POSITIVE_INFINITY
, Math
.abs( Number
.NEGATIVE_INFINITY
) );
65 array
[item
++] = new TestCase( SECTION
, "Math.abs( Infinity )", Number
.POSITIVE_INFINITY
, Math
.abs( Number
.POSITIVE_INFINITY
) );
66 array
[item
++] = new TestCase( SECTION
, "Math.abs( - MAX_VALUE )", Number
.MAX_VALUE
, Math
.abs( - Number
.MAX_VALUE
) );
67 array
[item
++] = new TestCase( SECTION
, "Math.abs( - MIN_VALUE )", Number
.MIN_VALUE
, Math
.abs( -Number
.MIN_VALUE
) );
68 array
[item
++] = new TestCase( SECTION
, "Math.abs( MAX_VALUE )", Number
.MAX_VALUE
, Math
.abs( Number
.MAX_VALUE
) );
69 array
[item
++] = new TestCase( SECTION
, "Math.abs( MIN_VALUE )", Number
.MIN_VALUE
, Math
.abs( Number
.MIN_VALUE
) );
71 array
[item
++] = new TestCase( SECTION
, "Math.abs( -1 )", 1, Math
.abs( -1 ) );
72 array
[item
++] = new TestCase( SECTION
, "Math.abs( new Number( -1 ) )", 1, Math
.abs( new Number(-1) ) );
73 array
[item
++] = new TestCase( SECTION
, "Math.abs( 1 )", 1, Math
.abs( 1 ) );
74 array
[item
++] = new TestCase( SECTION
, "Math.abs( Math.PI )", Math
.PI
, Math
.abs( Math
.PI
) );
75 array
[item
++] = new TestCase( SECTION
, "Math.abs( -Math.PI )", Math
.PI
, Math
.abs( -Math
.PI
) );
76 array
[item
++] = new TestCase( SECTION
, "Math.abs(-1/100000000)", 1/100000000, Math
.abs(-1/100000000) );
77 array
[item
++] = new TestCase( SECTION
, "Math.abs(-Math.pow(2,32))", Math
.pow(2,32), Math
.abs(-Math
.pow(2,32)) );
78 array
[item
++] = new TestCase( SECTION
, "Math.abs(Math.pow(2,32))", Math
.pow(2,32), Math
.abs(Math
.pow(2,32)) );
79 array
[item
++] = new TestCase( SECTION
, "Math.abs( -0xfff )", 4095, Math
.abs( -0xfff ) );
80 array
[item
++] = new TestCase( SECTION
, "Math.abs( -0777 )", 511, Math
.abs(-0777 ) );
82 array
[item
++] = new TestCase( SECTION
, "Math.abs('-1e-1')", 0.1, Math
.abs('-1e-1') );
83 array
[item
++] = new TestCase( SECTION
, "Math.abs('0xff')", 255, Math
.abs('0xff') );
84 array
[item
++] = new TestCase( SECTION
, "Math.abs('077')", 77, Math
.abs('077') );
85 array
[item
++] = new TestCase( SECTION
, "Math.abs( 'Infinity' )", Infinity
, Math
.abs('Infinity') );
86 array
[item
++] = new TestCase( SECTION
, "Math.abs( '-Infinity' )", Infinity
, Math
.abs('-Infinity') );
92 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
93 testcases
[tc
].passed
= writeTestCaseResult(
96 testcases
[tc
].description
+" = "+
97 testcases
[tc
].actual
);
99 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
102 return ( testcases
);