Files
playground-frontend/src/app/shared/fps-counter.spec.ts
T
lobo 833e1ec8dc feat(algorithms): add live metrics to algorithm pages
Each algorithm page shows its numbers with app-metrics.
FpsCounter publishes a rate every 500 ms, not every frame.
Fractal 2D reset now also resets the zoom slider.
2026-10-21 14:35:15 +02:00

31 lines
802 B
TypeScript

import {FpsCounter} from './fps-counter';
describe('FpsCounter', () => {
const FRAME_MS = 1000 / 60;
it('publishes 60 after the first 500 ms window and not before', () => {
const counter = new FpsCounter();
const at = (frame: number) => 1 + FRAME_MS * frame;
for (let frame = 0; at(frame) - 1 < 500; frame++) {
counter.tick(at(frame));
}
expect(counter.fps()).toBe(0);
counter.tick(at(30)); // 30 ticks since the window opened, 500 ms elapsed
expect(counter.fps()).toBe(60);
});
it('reset sets the rate back to 0', () => {
const counter = new FpsCounter();
for (let i = 0; i <= 61; i++) {
counter.tick(1 + FRAME_MS * i);
}
expect(counter.fps()).toBeGreaterThan(0);
counter.reset();
expect(counter.fps()).toBe(0);
});
});