1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2026-09-23 04:14:32 +00:00

Add immutability tests

This commit is contained in:
Michael Mclaughlin
2016-02-04 23:52:10 +00:00
parent a62bb62b6b
commit c2c4480881
59 changed files with 24997 additions and 24484 deletions

View File

@@ -1,32 +1,32 @@
if (typeof T === 'undefined') require('../setup');
(function () {
T('random');
T('random');
function tx(fn, msg) {
T.assertException(fn, msg);
function tx(fn, msg) {
T.assertException(fn, msg);
}
var i, sd, maxDigits = 100;
for (i = 0; i < 996; i++) {
Decimal.crypto = Math.random() > 0.5;
sd = Math.random() * maxDigits + 1 | 0;
if (Math.random() > 0.5) {
Decimal.precision = sd;
r = Decimal.random();
} else {
r = Decimal.random(sd);
}
var i, sd, maxDigits = 100;
T.assert(r.sd() <= sd && r.gte(0) && r.lt(1) && r.eq(r) && r.eq(r.valueOf()));
}
for (i = 0; i < 996; i++) {
Decimal.crypto = Math.random() > 0.5;
sd = Math.random() * maxDigits + 1 | 0;
tx(function () { Decimal.random(Infinity) }, 'Infinity');
tx(function () { Decimal.random('-Infinity') }, "'-Infinity'");
tx(function () { Decimal.random(NaN) }, 'NaN');
tx(function () { Decimal.random(null) }, 'null');
if (Math.random() > 0.5) {
Decimal.precision = sd;
r = Decimal.random();
} else {
r = Decimal.random(sd);
}
T.assert(r.sd() <= sd && r.gte(0) && r.lt(1) && r.eq(r) && r.eq(r.valueOf()));
}
tx(function () { Decimal.random(Infinity) }, 'Infinity');
tx(function () { Decimal.random('-Infinity') }, "'-Infinity'");
tx(function () { Decimal.random(NaN) }, 'NaN');
tx(function () { Decimal.random(null) }, 'null');
T.stop();
T.stop();
})();