25 lines
837 B
TypeScript
25 lines
837 B
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createFrameClock } from '../src/scene/frameClock.ts';
|
|
|
|
test('30 fps pacing retains elapsed simulation time on 60 and 120 Hz displays', () => {
|
|
for (const hz of [60, 120]) {
|
|
const clock = createFrameClock(30);
|
|
let frames = 0, elapsed = 0;
|
|
for (let i = 0; i <= hz * 10; i++) {
|
|
const delta = clock.tick(i * 1000 / hz);
|
|
if (delta !== undefined) { frames++; elapsed += delta; }
|
|
}
|
|
assert.equal(frames, 301);
|
|
assert.ok(Math.abs(elapsed - 10) < 1e-8);
|
|
}
|
|
});
|
|
|
|
test('resume resets elapsed time instead of simulating the hidden interval', () => {
|
|
const clock = createFrameClock(30);
|
|
clock.tick(0); clock.tick(100);
|
|
clock.reset();
|
|
assert.equal(clock.tick(60000), 0);
|
|
assert.equal(clock.tick(60001), undefined);
|
|
});
|