Home | History | Annotate | Download | only in Expressions
      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:          11.8.1.js
     24     ECMA Section:       11.8.1  The less-than operator ( < )
     25     Description:
     26 
     27 
     28     Author:             christine (at) netscape.com
     29     Date:               12 november 1997
     30 */
     31     var SECTION = "11.8.1";
     32     var VERSION = "ECMA_1";
     33     startTest();
     34     var testcases = getTestCases();
     35 
     36     writeHeaderToLog( SECTION + " The less-than operator ( < )");
     37     test();
     38 
     39 function test() {
     40     for ( tc=0; tc < testcases.length; tc++ ) {
     41         testcases[tc].passed = writeTestCaseResult(
     42                             testcases[tc].expect,
     43                             testcases[tc].actual,
     44                             testcases[tc].description +" = "+
     45                             testcases[tc].actual );
     46 
     47         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     48     }
     49     stopTest();
     50     return ( testcases );
     51 }
     52 function getTestCases() {
     53     var array = new Array();
     54     var item = 0;
     55 
     56     array[item++] = new TestCase( SECTION, "true < false",              false,      true < false );
     57     array[item++] = new TestCase( SECTION, "false < true",              true,       false < true );
     58     array[item++] = new TestCase( SECTION, "false < false",             false,      false < false );
     59     array[item++] = new TestCase( SECTION, "true < true",               false,      true < true );
     60 
     61     array[item++] = new TestCase( SECTION, "new Boolean(true) < new Boolean(true)",     false,  new Boolean(true) < new Boolean(true) );
     62     array[item++] = new TestCase( SECTION, "new Boolean(true) < new Boolean(false)",    false,  new Boolean(true) < new Boolean(false) );
     63     array[item++] = new TestCase( SECTION, "new Boolean(false) < new Boolean(true)",    true,   new Boolean(false) < new Boolean(true) );
     64     array[item++] = new TestCase( SECTION, "new Boolean(false) < new Boolean(false)",   false,  new Boolean(false) < new Boolean(false) );
     65 
     66     array[item++] = new TestCase( SECTION, "new MyObject(Infinity) < new MyObject(Infinity)",   false,  new MyObject( Number.POSITIVE_INFINITY ) < new MyObject( Number.POSITIVE_INFINITY) );
     67     array[item++] = new TestCase( SECTION, "new MyObject(-Infinity) < new MyObject(Infinity)",  true,   new MyObject( Number.NEGATIVE_INFINITY ) < new MyObject( Number.POSITIVE_INFINITY) );
     68     array[item++] = new TestCase( SECTION, "new MyObject(-Infinity) < new MyObject(-Infinity)", false,  new MyObject( Number.NEGATIVE_INFINITY ) < new MyObject( Number.NEGATIVE_INFINITY) );
     69 
     70     array[item++] = new TestCase( SECTION, "new MyValueObject(false) < new MyValueObject(true)",  true,   new MyValueObject(false) < new MyValueObject(true) );
     71     array[item++] = new TestCase( SECTION, "new MyValueObject(true) < new MyValueObject(true)",   false,  new MyValueObject(true) < new MyValueObject(true) );
     72     array[item++] = new TestCase( SECTION, "new MyValueObject(false) < new MyValueObject(false)", false,  new MyValueObject(false) < new MyValueObject(false) );
     73 
     74     array[item++] = new TestCase( SECTION, "new MyStringObject(false) < new MyStringObject(true)",  true,   new MyStringObject(false) < new MyStringObject(true) );
     75     array[item++] = new TestCase( SECTION, "new MyStringObject(true) < new MyStringObject(true)",   false,  new MyStringObject(true) < new MyStringObject(true) );
     76     array[item++] = new TestCase( SECTION, "new MyStringObject(false) < new MyStringObject(false)", false,  new MyStringObject(false) < new MyStringObject(false) );
     77 
     78     array[item++] = new TestCase( SECTION, "Number.NaN < Number.NaN",   false,     Number.NaN < Number.NaN );
     79     array[item++] = new TestCase( SECTION, "0 < Number.NaN",            false,     0 < Number.NaN );
     80     array[item++] = new TestCase( SECTION, "Number.NaN < 0",            false,     Number.NaN < 0 );
     81 
     82     array[item++] = new TestCase( SECTION, "0 < -0",                    false,      0 < -0 );
     83     array[item++] = new TestCase( SECTION, "-0 < 0",                    false,      -0 < 0 );
     84 
     85     array[item++] = new TestCase( SECTION, "Infinity < 0",                  false,      Number.POSITIVE_INFINITY < 0 );
     86     array[item++] = new TestCase( SECTION, "Infinity < Number.MAX_VALUE",   false,      Number.POSITIVE_INFINITY < Number.MAX_VALUE );
     87     array[item++] = new TestCase( SECTION, "Infinity < Infinity",           false,      Number.POSITIVE_INFINITY < Number.POSITIVE_INFINITY );
     88 
     89     array[item++] = new TestCase( SECTION, "0 < Infinity",                  true,       0 < Number.POSITIVE_INFINITY );
     90     array[item++] = new TestCase( SECTION, "Number.MAX_VALUE < Infinity",   true,       Number.MAX_VALUE < Number.POSITIVE_INFINITY );
     91 
     92     array[item++] = new TestCase( SECTION, "0 < -Infinity",                 false,      0 < Number.NEGATIVE_INFINITY );
     93     array[item++] = new TestCase( SECTION, "Number.MAX_VALUE < -Infinity",  false,      Number.MAX_VALUE < Number.NEGATIVE_INFINITY );
     94     array[item++] = new TestCase( SECTION, "-Infinity < -Infinity",         false,      Number.NEGATIVE_INFINITY < Number.NEGATIVE_INFINITY );
     95 
     96     array[item++] = new TestCase( SECTION, "-Infinity < 0",                 true,       Number.NEGATIVE_INFINITY < 0 );
     97     array[item++] = new TestCase( SECTION, "-Infinity < -Number.MAX_VALUE", true,       Number.NEGATIVE_INFINITY < -Number.MAX_VALUE );
     98     array[item++] = new TestCase( SECTION, "-Infinity < Number.MIN_VALUE",  true,       Number.NEGATIVE_INFINITY < Number.MIN_VALUE );
     99 
    100     array[item++] = new TestCase( SECTION, "'string' < 'string'",           false,       'string' < 'string' );
    101     array[item++] = new TestCase( SECTION, "'astring' < 'string'",          true,       'astring' < 'string' );
    102     array[item++] = new TestCase( SECTION, "'strings' < 'stringy'",         true,       'strings' < 'stringy' );
    103     array[item++] = new TestCase( SECTION, "'strings' < 'stringier'",       false,       'strings' < 'stringier' );
    104     array[item++] = new TestCase( SECTION, "'string' < 'astring'",          false,      'string' < 'astring' );
    105     array[item++] = new TestCase( SECTION, "'string' < 'strings'",          true,       'string' < 'strings' );
    106 
    107     return ( array );
    108 }
    109 function MyObject(value) {
    110     this.value = value;
    111     this.valueOf = new Function( "return this.value" );
    112     this.toString = new Function( "return this.value +''" );
    113 }
    114 function MyValueObject(value) {
    115     this.value = value;
    116     this.valueOf = new Function( "return this.value" );
    117 }
    118 function MyStringObject(value) {
    119     this.value = value;
    120     this.toString = new Function( "return this.value +''" );
    121 }