You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

30 lines
973 B

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)
assert counter.current_fps == counter.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.average_fps == pytest.approx(3.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)
counter.tick()
counter.tick()
counter.reset()
assert counter.current_fps == counter.average_fps == 0.0
assert counter.sample_count == 0
def test_invalid_window() -> None:
with pytest.raises(ValueError):
FPSCounter(0)