]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Math/15.8.2.17.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.17.js
24 ECMA Section: 15.8.2.17 Math.sqrt(x)
25 Description: return an approximation to the squareroot of the argument.
27 - if x is NaN return NaN
30 - if x == -0 return -0
31 - if x == Infinity return Infinity
32 Author: christine@netscape.com
36 var SECTION
= "15.8.2.17";
37 var VERSION
= "ECMA_1";
39 var TITLE
= "Math.sqrt(x)";
41 writeHeaderToLog( SECTION
+ " "+ TITLE
);
43 var testcases
= getTestCases();
46 function getTestCases() {
47 var array
= new Array();
50 array
[item
++] = new TestCase( SECTION
, "Math.sqrt.length", 1, Math
.sqrt
.length
);
52 array
[item
++] = new TestCase( SECTION
, "Math.sqrt()", Number
.NaN
, Math
.sqrt() );
53 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(void 0)", Number
.NaN
, Math
.sqrt(void 0) );
54 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(null)", 0, Math
.sqrt(null) );
55 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(true)", 1, Math
.sqrt(1) );
56 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(false)", 0, Math
.sqrt(false) );
57 array
[item
++] = new TestCase( SECTION
, "Math.sqrt('225')", 15, Math
.sqrt('225') );
59 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(NaN)", Number
.NaN
, Math
.sqrt(Number
.NaN
) );
60 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(-Infinity)", Number
.NaN
, Math
.sqrt(Number
.NEGATIVE_INFINITY
));
61 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(-1)", Number
.NaN
, Math
.sqrt(-1));
62 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(-0.5)", Number
.NaN
, Math
.sqrt(-0.5));
63 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(0)", 0, Math
.sqrt(0));
64 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(-0)", -0, Math
.sqrt(-0));
65 array
[item
++] = new TestCase( SECTION
, "Infinity/Math.sqrt(-0)", -Infinity
, Infinity
/Math
.sqrt(-0) );
66 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(Infinity)", Number
.POSITIVE_INFINITY
, Math
.sqrt(Number
.POSITIVE_INFINITY
));
67 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(1)", 1, Math
.sqrt(1));
68 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(2)", Math
.SQRT2
, Math
.sqrt(2));
69 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(0.5)", Math
.SQRT1_2
, Math
.sqrt(0.5));
70 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(4)", 2, Math
.sqrt(4));
71 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(9)", 3, Math
.sqrt(9));
72 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(16)", 4, Math
.sqrt(16));
73 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(25)", 5, Math
.sqrt(25));
74 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(36)", 6, Math
.sqrt(36));
75 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(49)", 7, Math
.sqrt(49));
76 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(64)", 8, Math
.sqrt(64));
77 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(256)", 16, Math
.sqrt(256));
78 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(10000)", 100, Math
.sqrt(10000));
79 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(65536)", 256, Math
.sqrt(65536));
80 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(0.09)", 0.3, Math
.sqrt(0.09));
81 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(0.01)", 0.1, Math
.sqrt(0.01));
82 array
[item
++] = new TestCase( SECTION
, "Math.sqrt(0.00000001)",0.0001, Math
.sqrt(0.00000001));
88 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
89 testcases
[tc
].passed
= writeTestCaseResult(
92 testcases
[tc
].description
+" = "+
93 testcases
[tc
].actual
);
95 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";