Initial Commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { Xoshiro256PlusPlusRng } from "./xoshiro256.js";
|
||||
|
||||
class ZeroXoshiro extends Xoshiro256PlusPlusRng {
|
||||
public constructor() {
|
||||
super(1);
|
||||
this.s0 = 0n;
|
||||
this.s1 = 0n;
|
||||
this.s2 = 0n;
|
||||
this.s3 = 0n;
|
||||
}
|
||||
public callEnsureNonZero(): void {
|
||||
this.ensureNonZeroState();
|
||||
}
|
||||
public readState(): [bigint, bigint, bigint, bigint] {
|
||||
return [this.s0, this.s1, this.s2, this.s3];
|
||||
}
|
||||
}
|
||||
|
||||
describe("Xoshiro256 ensureNonZeroState guard", () => {
|
||||
it("repairs an all-zero state by setting s0=1", { timeout: 5000 }, () => {
|
||||
const rng = new ZeroXoshiro();
|
||||
rng.callEnsureNonZero();
|
||||
expect(rng.readState()).toEqual([1n, 0n, 0n, 0n]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user