aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-12 19:47:59 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-12 19:47:59 +0100
commitf7b4866811c63ae24c366d9452e53d24e504336f (patch)
tree89ffd6cd9567e05ad010fbc0a1aef664d5740a2c /src/test
parenta464096dfff2ee4605e77852020e6a5c0fa5aa58 (diff)
fps fix + regression test
Diffstat (limited to 'src/test')
-rw-r--r--src/test/LoopTimerTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp
index 5e1eccf..c468567 100644
--- a/src/test/LoopTimerTest.cpp
+++ b/src/test/LoopTimerTest.cpp
@@ -76,3 +76,19 @@ TEST_F(LoopTimerTest, getCurrentTime) {
ASSERT_NEAR(loop_timer.get_elapsed_time().count(), elapsed_time, 5);
}
+TEST_F(LoopTimerTest, getFPS) {
+ // Set the target FPS to 60 (which gives a target time per frame of ~16.67 ms)
+ loop_timer.set_target_framerate(60);
+
+ auto start_time = steady_clock::now();
+ loop_timer.enforce_frame_rate();
+
+ auto elapsed_time = steady_clock::now() - start_time;
+ loop_timer.update();
+ unsigned int fps = loop_timer.get_fps();
+ auto elapsed_ms = duration_cast<milliseconds>(elapsed_time).count();
+
+ // For 60 FPS, the target frame time is around 16.67ms
+ ASSERT_NEAR(elapsed_ms, 16.7, 1);
+ ASSERT_NEAR(fps, 60, 2);
+}