chore: add more tests
This commit is contained in:
+45
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { createRNG } from '@/utils/rng';
|
||||
import { createRNG, Mulberry32RNG } from '@/utils/rng';
|
||||
|
||||
describe('createRNG', () => {
|
||||
it('should create RNG with default seed', () => {
|
||||
@@ -90,3 +90,47 @@ describe('createRNG', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Mulberry32RNG', () => {
|
||||
it('should instantiate with default seed', () => {
|
||||
const rng = new Mulberry32RNG();
|
||||
expect(rng.getSeed()).toBe(1);
|
||||
});
|
||||
|
||||
it('should instantiate with custom seed', () => {
|
||||
const rng = new Mulberry32RNG(99999);
|
||||
expect(rng.getSeed()).toBe(99999);
|
||||
});
|
||||
|
||||
it('should implement RNG interface', () => {
|
||||
const rng = new Mulberry32RNG(42);
|
||||
|
||||
// Should have all RNG methods
|
||||
expect(typeof rng.next).toBe('function');
|
||||
expect(typeof rng.nextInt).toBe('function');
|
||||
expect(typeof rng.setSeed).toBe('function');
|
||||
expect(typeof rng.getSeed).toBe('function');
|
||||
});
|
||||
|
||||
it('should produce same results as createRNG with same seed', () => {
|
||||
const factoryRng = createRNG(12345);
|
||||
const directRng = new Mulberry32RNG(12345);
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
expect(factoryRng.next()).toBe(directRng.next());
|
||||
expect(factoryRng.nextInt(100)).toBe(directRng.nextInt(100));
|
||||
}
|
||||
});
|
||||
|
||||
it('should allow seed changes after instantiation', () => {
|
||||
const rng = new Mulberry32RNG(100);
|
||||
expect(rng.getSeed()).toBe(100);
|
||||
|
||||
rng.setSeed(200);
|
||||
expect(rng.getSeed()).toBe(200);
|
||||
|
||||
const value = rng.next();
|
||||
expect(value).toBeGreaterThanOrEqual(0);
|
||||
expect(value).toBeLessThan(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user