Home | History | Annotate | Download | only in Math
      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.4.js
     24     ECMA Section:       15.8.2.4 atan( x )
     25     Description:        return an approximation to the arc tangent of the
     26                         argument.  the result is expressed in radians and
     27                         range is from -PI/2 to +PI/2.  special cases:
     28                         - if x is NaN,  the result is NaN
     29                         - if x == +0,   the result is +0
     30                         - if x == -0,   the result is -0
     31                         - if x == +Infinity,    the result is approximately +PI/2
     32                         - if x == -Infinity,    the result is approximately -PI/2
     33     Author:             christine (at) netscape.com
     34     Date:               7 july 1997
     35 
     36 */
     37 
     38     var SECTION = "15.8.2.4";
     39     var VERSION = "ECMA_1";
     40     startTest();
     41     var TITLE   = "Math.atan()";
     42     var BUGNUMBER="77391";
     43 
     44     writeHeaderToLog( SECTION + " "+ TITLE);
     45 
     46     var testcases = getTestCases();
     47     test();
     48 
     49 function getTestCases() {
     50     var array = new Array();
     51     var item = 0;
     52 
     53     array[item++] = new TestCase( SECTION,   "Math.atan.length",        1,              Math.atan.length );
     54 
     55     array[item++] = new TestCase( SECTION,   "Math.atan()",             Number.NaN,     Math.atan() );
     56     array[item++] = new TestCase( SECTION,   "Math.atan(void 0)",       Number.NaN,     Math.atan(void 0) );
     57     array[item++] = new TestCase( SECTION,   "Math.atan(null)",         0,              Math.atan(null) );
     58     array[item++] = new TestCase( SECTION,   "Math.atan(NaN)",          Number.NaN,     Math.atan(Number.NaN) );
     59 
     60     array[item++] = new TestCase( SECTION,   "Math.atan('a string')",   Number.NaN,     Math.atan("a string") );
     61     array[item++] = new TestCase( SECTION,   "Math.atan('0')",          0,              Math.atan('0') );
     62     array[item++] = new TestCase( SECTION,   "Math.atan('1')",          Math.PI/4,      Math.atan('1') );
     63     array[item++] = new TestCase( SECTION,   "Math.atan('-1')",         -Math.PI/4,     Math.atan('-1') );
     64     array[item++] = new TestCase( SECTION,   "Math.atan('Infinity)",    Math.PI/2,      Math.atan('Infinity') );
     65     array[item++] = new TestCase( SECTION,   "Math.atan('-Infinity)",   -Math.PI/2,     Math.atan('-Infinity') );
     66 
     67     array[item++] = new TestCase( SECTION,   "Math.atan(0)",            0,              Math.atan(0)          );
     68     array[item++] = new TestCase( SECTION,   "Math.atan(-0)",	        -0,             Math.atan(-0)         );
     69     array[item++] = new TestCase( SECTION,   "Infinity/Math.atan(-0)",  -Infinity,      Infinity/Math.atan(-0) );
     70     array[item++] = new TestCase( SECTION,   "Math.atan(Infinity)",     Math.PI/2,      Math.atan(Number.POSITIVE_INFINITY) );
     71     array[item++] = new TestCase( SECTION,   "Math.atan(-Infinity)",    -Math.PI/2,     Math.atan(Number.NEGATIVE_INFINITY) );
     72     array[item++] = new TestCase( SECTION,   "Math.atan(1)",     	    Math.PI/4,      Math.atan(1)          );
     73     array[item++] = new TestCase( SECTION,   "Math.atan(-1)",           -Math.PI/4,     Math.atan(-1)         );
     74     return array;
     75 }
     76 function test() {
     77     for ( tc=0; tc < testcases.length; tc++ ) {
     78         testcases[tc].passed = writeTestCaseResult(
     79                             testcases[tc].expect,
     80                             testcases[tc].actual,
     81                             testcases[tc].description +" = "+
     82                             testcases[tc].actual );
     83 
     84         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     85     }
     86     stopTest();
     87     return ( testcases );
     88 }