refactor: tighten core seams and spawning

This commit is contained in:
2026-06-18 18:34:45 +03:00
parent 58bf96e9d9
commit b7362a2ad8
11 changed files with 222 additions and 24 deletions
+17
View File
@@ -41,4 +41,21 @@ describe('Rng', () => {
const shuffled = r.shuffle([...arr]);
expect([...shuffled].sort()).toEqual(arr);
});
it('авто-seed не вызывает Math.random()', () => {
const math = Math as Math & { random: () => number };
const original = math.random;
math.random = () => { throw new Error('Math.random вызван'); };
try {
const r = new Rng();
expect(r.next()).toBeGreaterThanOrEqual(0);
expect(r.next()).toBeLessThan(1);
} finally {
math.random = original;
}
});
it('pick явно ругается на пустой массив', () => {
expect(() => new Rng(1).pick([])).toThrow('пустой массив');
});
});