~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/JavaScriptCore/tests/mozilla/ecma/Math/15.8.2.1.js

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.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
 
27
                        with a positive sign.
 
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
 
32
    Date:               7 july 1997
 
33
*/
 
34
    var SECTION = "15.8.2.1";
 
35
    var VERSION = "ECMA_1";
 
36
    startTest();
 
37
    var TITLE   = "Math.abs()";
 
38
    var BUGNUMBER = "77391";
 
39
 
 
40
    writeHeaderToLog( SECTION + " "+ TITLE);
 
41
 
 
42
    var testcases = getTestCases();
 
43
    test();
 
44
 
 
45
function getTestCases() {
 
46
    var array = new Array();
 
47
    var item = 0;
 
48
 
 
49
    array[item++] = new TestCase( SECTION,   "Math.abs.length",             1,              Math.abs.length );
 
50
 
 
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) );
 
59
 
 
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) );
 
63
 
 
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 )        );
 
70
 
 
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 ) );
 
81
 
 
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') );
 
87
 
 
88
    return ( array );
 
89
}
 
90
 
 
91
function test() {
 
92
    for ( tc=0; tc < testcases.length; tc++ ) {
 
93
        testcases[tc].passed = writeTestCaseResult(
 
94
                            testcases[tc].expect,
 
95
                            testcases[tc].actual,
 
96
                            testcases[tc].description +" = "+
 
97
                            testcases[tc].actual );
 
98
 
 
99
        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
 
100
    }
 
101
    stopTest();
 
102
    return ( testcases );
 
103
}