Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Jan 8, 2025
1 parent 9d901b5 commit d5a34be
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/sim/prng.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const assert = require('./../assert');
const {PRNG} = require('../../dist/sim');

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

0 comments on commit d5a34be

Please sign in to comment.