1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Math/15.8.2.15.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,168 @@ 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.15.js 1.12 + ECMA Section: 15.8.2.15 Math.round(x) 1.13 + Description: return the greatest number value that is closest to the 1.14 + argument and is an integer. if two integers are equally 1.15 + close to the argument. then the result is the number value 1.16 + that is closer to Infinity. if the argument is an integer, 1.17 + return the argument. 1.18 + special cases: 1.19 + - if x is NaN return NaN 1.20 + - if x = +0 return +0 1.21 + - if x = -0 return -0 1.22 + - if x = Infinity return Infinity 1.23 + - if x = -Infinity return -Infinity 1.24 + - if 0 < x < 0.5 return 0 1.25 + - if -0.5 <= x < 0 return -0 1.26 + example: 1.27 + Math.round( 3.5 ) == 4 1.28 + Math.round( -3.5 ) == 3 1.29 + also: 1.30 + - Math.round(x) == Math.floor( x + 0.5 ) 1.31 + except if x = -0. in that case, Math.round(x) = -0 1.32 + 1.33 + and Math.floor( x+0.5 ) = +0 1.34 + 1.35 + 1.36 + Author: christine@netscape.com 1.37 + Date: 7 july 1997 1.38 +*/ 1.39 + 1.40 +var SECTION = "15.8.2.15"; 1.41 +var VERSION = "ECMA_1"; 1.42 +var TITLE = "Math.round(x)"; 1.43 +var BUGNUMBER="331411"; 1.44 + 1.45 +var EXCLUDE = "true"; 1.46 + 1.47 +startTest(); 1.48 + 1.49 +writeHeaderToLog( SECTION + " "+ TITLE); 1.50 + 1.51 +new TestCase( SECTION, 1.52 + "Math.round.length", 1.53 + 1, 1.54 + Math.round.length ); 1.55 + 1.56 +new TestCase( SECTION, 1.57 + "Math.round()", 1.58 + Number.NaN, 1.59 + Math.round() ); 1.60 + 1.61 +new TestCase( SECTION, 1.62 + "Math.round(null)", 1.63 + 0, 1.64 + Math.round(0) ); 1.65 + 1.66 +new TestCase( SECTION, 1.67 + "Math.round(void 0)", 1.68 + Number.NaN, 1.69 + Math.round(void 0) ); 1.70 + 1.71 +new TestCase( SECTION, 1.72 + "Math.round(true)", 1.73 + 1, 1.74 + Math.round(true) ); 1.75 + 1.76 +new TestCase( SECTION, 1.77 + "Math.round(false)", 1.78 + 0, 1.79 + Math.round(false) ); 1.80 + 1.81 +new TestCase( SECTION, 1.82 + "Math.round('.99999')", 1.83 + 1, 1.84 + Math.round('.99999') ); 1.85 + 1.86 +new TestCase( SECTION, 1.87 + "Math.round('12345e-2')", 1.88 + 123, 1.89 + Math.round('12345e-2') ); 1.90 + 1.91 +new TestCase( SECTION, 1.92 + "Math.round(NaN)", 1.93 + Number.NaN, 1.94 + Math.round(Number.NaN) ); 1.95 + 1.96 +new TestCase( SECTION, 1.97 + "Math.round(0)", 1.98 + 0, 1.99 + Math.round(0) ); 1.100 + 1.101 +new TestCase( SECTION, 1.102 + "Math.round(-0)", 1.103 + -0, 1.104 + Math.round(-0)); 1.105 + 1.106 +new TestCase( SECTION, 1.107 + "Infinity/Math.round(-0)", 1.108 + -Infinity, 1.109 + Infinity/Math.round(-0) ); 1.110 + 1.111 +new TestCase( SECTION, 1.112 + "Math.round(Infinity)", 1.113 + Number.POSITIVE_INFINITY, 1.114 + Math.round(Number.POSITIVE_INFINITY)); 1.115 + 1.116 +new TestCase( SECTION, 1.117 + "Math.round(-Infinity)", 1.118 + Number.NEGATIVE_INFINITY, 1.119 + Math.round(Number.NEGATIVE_INFINITY)); 1.120 + 1.121 +new TestCase( SECTION, 1.122 + "Math.round(0.49)", 1.123 + 0, 1.124 + Math.round(0.49)); 1.125 + 1.126 +new TestCase( SECTION, 1.127 + "Math.round(0.5)", 1.128 + 1, 1.129 + Math.round(0.5)); 1.130 + 1.131 +new TestCase( SECTION, 1.132 + "Math.round(0.51)", 1.133 + 1, 1.134 + Math.round(0.51)); 1.135 + 1.136 +new TestCase( SECTION, 1.137 + "Math.round(-0.49)", 1.138 + -0, 1.139 + Math.round(-0.49)); 1.140 + 1.141 +new TestCase( SECTION, 1.142 + "Math.round(-0.5)", 1.143 + -0, 1.144 + Math.round(-0.5)); 1.145 + 1.146 +new TestCase( SECTION, 1.147 + "Infinity/Math.round(-0.49)", 1.148 + -Infinity, 1.149 + Infinity/Math.round(-0.49)); 1.150 + 1.151 +new TestCase( SECTION, 1.152 + "Infinity/Math.round(-0.5)", 1.153 + -Infinity, 1.154 + Infinity/Math.round(-0.5)); 1.155 + 1.156 +new TestCase( SECTION, 1.157 + "Math.round(-0.51)", 1.158 + -1, 1.159 + Math.round(-0.51)); 1.160 + 1.161 +new TestCase( SECTION, 1.162 + "Math.round(3.5)", 1.163 + 4, 1.164 + Math.round(3.5)); 1.165 + 1.166 +new TestCase( SECTION, 1.167 + "Math.round(-3.5)", 1.168 + -3, 1.169 + Math.round(-3)); 1.170 + 1.171 +test();