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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
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.
26                        special cases:
27                        -   if x is NaN         return NaN
28                        -   if x < 0            return NaN
29                        -   if x == 0           return 0
30                        -   if x == -0          return -0
31                        -   if x == Infinity    return Infinity
32    Author:             christine@netscape.com
33    Date:               7 july 1997
34*/
35
36    var SECTION = "15.8.2.17";
37    var VERSION = "ECMA_1";
38    startTest();
39    var TITLE   = "Math.sqrt(x)";
40
41    writeHeaderToLog( SECTION + " "+ TITLE);
42
43    var testcases = getTestCases();
44    test();
45
46function getTestCases() {
47    var array = new Array();
48    var item = 0;
49
50    array[item++] = new TestCase( SECTION,  "Math.sqrt.length",     1,              Math.sqrt.length );
51
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') );
58
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));
83
84    return ( array );
85}
86
87function test() {
88    for ( tc=0; tc < testcases.length; tc++ ) {
89        testcases[tc].passed = writeTestCaseResult(
90                            testcases[tc].expect,
91                            testcases[tc].actual,
92                            testcases[tc].description +" = "+
93                            testcases[tc].actual );
94
95        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
96    }
97    stopTest();
98    return ( testcases );
99}