UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

52 lines 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mocha_1 = require("mocha"); const chai_1 = require("chai"); const rng_1 = require("../src/rng"); function testForRange(rng, bound, nsamples) { for (let i = 0; i < nsamples; i++) { const state = rng.getState(); const v = rng.next(bound); (0, chai_1.assert)(0n <= v && v < bound, `${v} is not in the range [0, ${bound}), state = ${state}`); } } (0, mocha_1.describe)('rng', () => { (0, mocha_1.it)('produces an expected sequence', () => { const rng = (0, rng_1.newRng)(20230404n); (0, chai_1.expect)(rng.next(1000n)).to.equal(314n); (0, chai_1.expect)(rng.next(2000n)).to.equal(103n); (0, chai_1.expect)(rng.next(3000n)).to.equal(1254n); (0, chai_1.expect)(rng.next(2n ** 256n)).to.equal(39968831094728793095337668312741798650168913551481632943502796831606193252535n); }); (0, mocha_1.it)('produces big integers in [0, 10000)', () => { testForRange((0, rng_1.newRng)(), 10000n, 100000); }); (0, mocha_1.it)('produces big integers in [0, 2^16)', () => { testForRange((0, rng_1.newRng)(), 2n ** 16n, 10000); }); (0, mocha_1.it)('produces big integers in [0, 2^32)', () => { testForRange((0, rng_1.newRng)(), 2n ** 32n, 10000); }); (0, mocha_1.it)('produces big integers in [0, 2^32 + 1))', () => { testForRange((0, rng_1.newRng)(), 2n ** 32n + 1n, 10000); }); (0, mocha_1.it)('produces big integers in [0, 2^64))', () => { testForRange((0, rng_1.newRng)(), 2n ** 64n, 10000); }); (0, mocha_1.it)('produces big integers in [0, 2^64 + 1))', () => { testForRange((0, rng_1.newRng)(), 2n ** 64n + 1n, 10000); }); (0, mocha_1.it)('produces big integers in [0, over 2^64))', () => { testForRange((0, rng_1.newRng)(), 2n ** 64n + 3n * 5n * 7n * 11n, 10000); }); (0, mocha_1.it)('produces big integers in [0, 2^96 + 1))', () => { testForRange((0, rng_1.newRng)(), 2n ** 96n + 1n, 10000); }); (0, mocha_1.it)('produces big integers in [0, over 2^96))', () => { testForRange((0, rng_1.newRng)(), 2n ** 96n + 3n * 5n * 7n * 11n, 10000); }); (0, mocha_1.it)('produces big integers in [0, over 2^256))', () => { testForRange((0, rng_1.newRng)(), 2n ** 256n + 2n ** 33n + 11n, 10000); }); }); //# sourceMappingURL=rng.test.js.map