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 0c2c4a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sim/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class Battle {

this.send = options.send || (() => {});

const inputOptions: {formatid: ID, seed: PRNGSeed, rated?: string | true} = {
const inputOptions: {formatid: ID, seed: PRNGSeed | Buffer, rated?: string | true} = {
formatid: options.formatid, seed: this.prng.seed,
};
if (this.rated) inputOptions.rated = this.rated;
Expand Down
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 0c2c4a8

Please sign in to comment.