• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if (typeof T === 'undefined') require('../setup');
2
3T('random', function () {
4  var i, sd, maxDigits;
5
6  function tx(fn, msg) {
7    T.assertException(fn, msg);
8  }
9
10  maxDigits = 100;
11
12  for (i = 0; i < 996; i++) {
13    sd = Math.random() * maxDigits + 1 | 0;
14
15    if (Math.random() > 0.5) {
16      Decimal.precision = sd;
17      r = Decimal.random();
18    } else {
19      r = Decimal.random(sd);
20    }
21
22    T.assert(r.sd() <= sd && r.gte(0) && r.lt(1) && r.eq(r) && r.eq(r.valueOf()));
23  }
24
25  tx(function () { Decimal.random(Infinity) }, 'Infinity');
26  tx(function () { Decimal.random('-Infinity') }, "'-Infinity'");
27  tx(function () { Decimal.random(NaN) }, 'NaN');
28  tx(function () { Decimal.random(null) }, 'null');
29});
30