js/src/tests/ecma_6/Math/trunc.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // If x is NaN, the result is NaN.
michael@0 2 assertEq(Math.trunc(NaN), NaN);
michael@0 3
michael@0 4 // If x is −0, the result is −0.
michael@0 5 assertEq(Math.trunc(-0), -0);
michael@0 6
michael@0 7 // If x is +0, the result is +0.
michael@0 8 assertEq(Math.trunc(+0), +0);
michael@0 9
michael@0 10 // If x is +∞, the result is +∞.
michael@0 11 assertEq(Math.trunc(Infinity), Infinity);
michael@0 12
michael@0 13 // If x is −∞, the result is −∞.
michael@0 14 assertEq(Math.trunc(-Infinity), -Infinity);
michael@0 15
michael@0 16 // Other boundary cases.
michael@0 17 var MAX_NONINTEGER_VALUE = 4503599627370495.5;
michael@0 18 var TRUNC_MAX_NONINTEGER_VALUE = 4503599627370495;
michael@0 19
michael@0 20 assertEq(Math.trunc(Number.MIN_VALUE), +0);
michael@0 21 assertEq(Math.trunc(ONE_MINUS_EPSILON), +0);
michael@0 22 assertEq(Math.trunc(ONE_PLUS_EPSILON), 1);
michael@0 23 assertEq(Math.trunc(MAX_NONINTEGER_VALUE), TRUNC_MAX_NONINTEGER_VALUE);
michael@0 24 assertEq(Math.trunc(Number.MAX_VALUE), Number.MAX_VALUE);
michael@0 25
michael@0 26 assertEq(Math.trunc(-Number.MIN_VALUE), -0);
michael@0 27 assertEq(Math.trunc(-ONE_MINUS_EPSILON), -0);
michael@0 28 assertEq(Math.trunc(-ONE_PLUS_EPSILON), -1);
michael@0 29 assertEq(Math.trunc(-MAX_NONINTEGER_VALUE), -TRUNC_MAX_NONINTEGER_VALUE);
michael@0 30 assertEq(Math.trunc(-Number.MAX_VALUE), -Number.MAX_VALUE);
michael@0 31
michael@0 32 // Other cases.
michael@0 33 for (var i = 1, f = 1.1; i < 20; i++, f += 1.0)
michael@0 34 assertEq(Math.trunc(f), i);
michael@0 35
michael@0 36 for (var i = -1, f = -1.1; i > -20; i--, f -= 1.0)
michael@0 37 assertEq(Math.trunc(f), i);
michael@0 38
michael@0 39 assertEq(Math.trunc(1e40 + 0.5), 1e40);
michael@0 40
michael@0 41 assertEq(Math.trunc(1e300), 1e300);
michael@0 42 assertEq(Math.trunc(-1e300), -1e300);
michael@0 43 assertEq(Math.trunc(1e-300), 0);
michael@0 44 assertEq(Math.trunc(-1e-300), -0);
michael@0 45
michael@0 46 assertEq(Math.trunc(+0.9999), +0);
michael@0 47 assertEq(Math.trunc(-0.9999), -0);
michael@0 48
michael@0 49
michael@0 50 reportCompare(0, 0, "ok");

mercurial