32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import pytest
|
|
|
|
from src.fps_counter import FPSCounter
|
|
|
|
|
|
def test_initial_and_tick_and_average(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
times = iter([1.0, 1.5, 1.75])
|
|
monkeypatch.setattr("src.fps_counter.time.perf_counter", lambda: next(times))
|
|
counter = FPSCounter(2, 2)
|
|
assert counter.current_fps == counter.recent_average_fps == 0.0
|
|
assert counter.tick() == 0.0
|
|
assert counter.tick() == pytest.approx(2.0)
|
|
assert counter.tick() == pytest.approx(4.0)
|
|
assert counter.sample_count == 1
|
|
assert counter.average_fps == pytest.approx(4.0)
|
|
assert counter.recent_average_fps == pytest.approx(4.0)
|
|
|
|
|
|
def test_reset(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
times = iter([1.0, 2.0])
|
|
monkeypatch.setattr("src.fps_counter.time.perf_counter", lambda: next(times))
|
|
counter = FPSCounter(3, 0)
|
|
counter.tick()
|
|
counter.tick()
|
|
counter.reset()
|
|
assert counter.current_fps == counter.recent_average_fps == 0.0
|
|
assert counter.sample_count == 0
|
|
|
|
|
|
def test_invalid_window() -> None:
|
|
with pytest.raises(ValueError):
|
|
FPSCounter(0, 0) |