js/src/tests/ecma/Math/15.8.2.9.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Math/15.8.2.9.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,157 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          15.8.2.9.js
    1.12 +   ECMA Section:       15.8.2.9  Math.floor(x)
    1.13 +   Description:        return the greatest number value that is not greater
    1.14 +   than the argument and is equal to a mathematical integer.
    1.15 +   if the number is already an integer, return the number
    1.16 +   itself.  special cases:
    1.17 +   - if x is NaN       return NaN
    1.18 +   - if x = +0         return +0
    1.19 +   - if x = -0          return -0
    1.20 +   - if x = Infinity   return Infinity
    1.21 +   - if x = -Infinity  return -Infinity
    1.22 +   - if ( -1 < x < 0 ) return -0
    1.23 +   also:
    1.24 +   -   the value of Math.floor(x) == -Math.ceil(-x)
    1.25 +   Author:             christine@netscape.com
    1.26 +   Date:               7 july 1997
    1.27 +*/
    1.28 +
    1.29 +var SECTION = "15.8.2.9";
    1.30 +var VERSION = "ECMA_1";
    1.31 +startTest();
    1.32 +var TITLE   = "Math.floor(x)";
    1.33 +
    1.34 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.35 +
    1.36 +new TestCase( SECTION,
    1.37 +	      "Math.floor.length",
    1.38 +	      1,
    1.39 +	      Math.floor.length );
    1.40 +
    1.41 +new TestCase( SECTION,
    1.42 +	      "Math.floor()",
    1.43 +	      Number.NaN,
    1.44 +	      Math.floor() );
    1.45 +
    1.46 +new TestCase( SECTION,
    1.47 +	      "Math.floor(void 0)",
    1.48 +	      Number.NaN,
    1.49 +	      Math.floor(void 0) );
    1.50 +
    1.51 +new TestCase( SECTION,
    1.52 +	      "Math.floor(null)",
    1.53 +	      0,
    1.54 +	      Math.floor(null) );
    1.55 +
    1.56 +new TestCase( SECTION,
    1.57 +	      "Math.floor(true)",
    1.58 +	      1,
    1.59 +	      Math.floor(true) );
    1.60 +
    1.61 +new TestCase( SECTION,
    1.62 +	      "Math.floor(false)",
    1.63 +	      0,
    1.64 +	      Math.floor(false) );
    1.65 +
    1.66 +new TestCase( SECTION,
    1.67 +	      "Math.floor('1.1')",
    1.68 +	      1,
    1.69 +	      Math.floor("1.1") );
    1.70 +
    1.71 +new TestCase( SECTION,
    1.72 +	      "Math.floor('-1.1')",
    1.73 +	      -2,
    1.74 +	      Math.floor("-1.1") );
    1.75 +
    1.76 +new TestCase( SECTION,
    1.77 +	      "Math.floor('0.1')",
    1.78 +	      0,
    1.79 +	      Math.floor("0.1") );
    1.80 +
    1.81 +new TestCase( SECTION,
    1.82 +	      "Math.floor('-0.1')",
    1.83 +	      -1,
    1.84 +	      Math.floor("-0.1") );
    1.85 +
    1.86 +new TestCase( SECTION,
    1.87 +	      "Math.floor(NaN)",
    1.88 +	      Number.NaN,
    1.89 +	      Math.floor(Number.NaN)  );
    1.90 +
    1.91 +new TestCase( SECTION,
    1.92 +	      "Math.floor(NaN)==-Math.ceil(-NaN)",
    1.93 +	      false,
    1.94 +	      Math.floor(Number.NaN) == -Math.ceil(-Number.NaN) );
    1.95 +
    1.96 +new TestCase( SECTION,
    1.97 +	      "Math.floor(0)",
    1.98 +	      0,
    1.99 +	      Math.floor(0)           );
   1.100 +
   1.101 +new TestCase( SECTION,
   1.102 +	      "Math.floor(0)==-Math.ceil(-0)",
   1.103 +	      true,
   1.104 +	      Math.floor(0) == -Math.ceil(-0) );
   1.105 +
   1.106 +new TestCase( SECTION,
   1.107 +	      "Math.floor(-0)",
   1.108 +	      -0,
   1.109 +	      Math.floor(-0)          );
   1.110 +
   1.111 +new TestCase( SECTION,
   1.112 +	      "Infinity/Math.floor(-0)",
   1.113 +	      -Infinity,
   1.114 +	      Infinity/Math.floor(-0)          );
   1.115 +
   1.116 +new TestCase( SECTION,
   1.117 +	      "Math.floor(-0)==-Math.ceil(0)",
   1.118 +	      true,
   1.119 +	      Math.floor(-0)== -Math.ceil(0) );
   1.120 +
   1.121 +new TestCase( SECTION,
   1.122 +	      "Math.floor(Infinity)",
   1.123 +	      Number.POSITIVE_INFINITY,
   1.124 +	      Math.floor(Number.POSITIVE_INFINITY) );
   1.125 +
   1.126 +new TestCase( SECTION,
   1.127 +	      "Math.floor(Infinity)==-Math.ceil(-Infinity)",
   1.128 +	      true,
   1.129 +	      Math.floor(Number.POSITIVE_INFINITY) == -Math.ceil(Number.NEGATIVE_INFINITY) );
   1.130 +
   1.131 +new TestCase( SECTION,
   1.132 +	      "Math.floor(-Infinity)",
   1.133 +	      Number.NEGATIVE_INFINITY,
   1.134 +	      Math.floor(Number.NEGATIVE_INFINITY) );
   1.135 +
   1.136 +new TestCase( SECTION,
   1.137 +	      "Math.floor(-Infinity)==-Math.ceil(Infinity)",
   1.138 +	      true,
   1.139 +	      Math.floor(Number.NEGATIVE_INFINITY) == -Math.ceil(Number.POSITIVE_INFINITY) );
   1.140 +
   1.141 +new TestCase( SECTION,
   1.142 +	      "Math.floor(0.0000001)",
   1.143 +	      0,
   1.144 +	      Math.floor(0.0000001) );
   1.145 +
   1.146 +new TestCase( SECTION,
   1.147 +	      "Math.floor(0.0000001)==-Math.ceil(0.0000001)", true,
   1.148 +	      Math.floor(0.0000001)==-Math.ceil(-0.0000001) );
   1.149 +
   1.150 +new TestCase( SECTION,
   1.151 +	      "Math.floor(-0.0000001)",
   1.152 +	      -1,
   1.153 +	      Math.floor(-0.0000001) );
   1.154 +
   1.155 +new TestCase( SECTION,
   1.156 +	      "Math.floor(0.0000001)==-Math.ceil(0.0000001)",
   1.157 +	      true,
   1.158 +	      Math.floor(-0.0000001)==-Math.ceil(0.0000001) );
   1.159 +
   1.160 +test();

mercurial