Skip to content

Commit

Permalink
Actually test the new PRNG
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Jan 10, 2025
1 parent 8b5710e commit 5617534
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/sim/misc/prng.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@
const PRNG = require('../../../dist/sim/prng').PRNG;
const assert = require('../../assert');

const testSeed = [1, 2, 3, 4];
const testSeed = ['sodium', 1, 2, 3, 4];

describe(`PRNG`, function () {
it("should always generate the same results off the same seed", function () {
const results = [];
const testAgainst = new PRNG(testSeed);
for (let i = 0; i < 100; i++) {
results.push(testAgainst.next());
}
for (let i = 0; i < 10; i++) {
const cur = new PRNG(testSeed);
for (let j = 0; j < results.length; j++) {
const n = cur.next();
assert(results[j] === n, `generation ${j} for seed ${testSeed} did not match (expected: ${results[j]}, got ${n})`);
}
}
});

describe(`randomChance(numerator=0, denominator=1)`, function () {
it(`should always return false`, function () {
const prng = new PRNG(testSeed);
Expand Down

0 comments on commit 5617534

Please sign in to comment.