diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-07 14:19:16 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-07 14:19:16 +0100 |
commit | a73ff31b67faa7e6a922cfb5598f56f80bc01d62 (patch) | |
tree | 04840dfbdbe6207100fbbc2aba04f48a46de1022 /src/test/LoopTimerTest.cpp | |
parent | a0070890fcdb422db85660fc44bcc709832870b8 (diff) |
added loopTimer and eventManager to mediator and removed the singletons
Diffstat (limited to 'src/test/LoopTimerTest.cpp')
-rw-r--r-- | src/test/LoopTimerTest.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp index 7652093..09b4e00 100644 --- a/src/test/LoopTimerTest.cpp +++ b/src/test/LoopTimerTest.cpp @@ -1,16 +1,17 @@ #include <chrono> -#include <gtest/gtest.h> #include <thread> +#include <gtest/gtest.h> #define private public #define protected public -#include "api/LoopTimer.h" - +#include <crepe/manager/LoopTimerManager.h> +#include <crepe/manager/Mediator.h> using namespace std::chrono; using namespace crepe; class LoopTimerTest : public ::testing::Test { protected: - LoopTimer loop_timer; + Mediator mediator; + LoopTimerManager loop_timer{mediator}; void SetUp() override { loop_timer.start(); } }; @@ -25,8 +26,7 @@ TEST_F(LoopTimerTest, EnforcesTargetFrameRate) { auto elapsed_ms = duration_cast<milliseconds>(elapsed_time).count(); // For 60 FPS, the target frame time is around 16.67ms - ASSERT_GE(elapsed_ms, 16); // Make sure it's at least 16 ms (could be slightly more) - ASSERT_LE(elapsed_ms, 18); // Ensure it's not too much longer + ASSERT_NEAR(elapsed_ms,16.7,1); } TEST_F(LoopTimerTest, SetTargetFps) { // Set the target FPS to 120 @@ -48,11 +48,10 @@ TEST_F(LoopTimerTest, DeltaTimeCalculation) { // Check the delta time double delta_time = loop_timer.get_delta_time(); - auto elapsed_time = duration_cast<milliseconds>(end_time - start_time).count(); + auto elapsed_time = duration_cast<seconds>(end_time - start_time).count(); // Assert that delta_time is close to the elapsed time - ASSERT_GE(delta_time, elapsed_time / 1000.0); - ASSERT_LE(delta_time, (elapsed_time + 2) / 1000.0); + ASSERT_NEAR(delta_time, elapsed_time, 1); } TEST_F(LoopTimerTest, getCurrentTime) { |