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