From 6f4fc75b66e82251619472bd58debcf5d8dcc96a Mon Sep 17 00:00:00 2001 From: Patedam Date: Sat, 7 Feb 2026 18:22:45 -0500 Subject: [PATCH] Added support for easily adding unit tests. made by gemini, there is a mistake vector test are verifying std, but will be changed next iteration --- Juliet/src/Engine/Engine.cpp | 9 +++ .../src/UnitTest/Container/VectorUnitTest.cpp | 57 +++++++++++++++++++ Juliet/src/UnitTest/RunUnitTests.cpp | 23 ++++++++ 3 files changed, 89 insertions(+) create mode 100644 Juliet/src/UnitTest/Container/VectorUnitTest.cpp create mode 100644 Juliet/src/UnitTest/RunUnitTests.cpp diff --git a/Juliet/src/Engine/Engine.cpp b/Juliet/src/Engine/Engine.cpp index c37685c..7c3b72a 100644 --- a/Juliet/src/Engine/Engine.cpp +++ b/Juliet/src/Engine/Engine.cpp @@ -17,6 +17,10 @@ namespace Juliet { + #ifdef JULIET_DEBUG + extern void RunUnitTests(); + #endif + namespace { Engine EngineInstance; @@ -131,6 +135,11 @@ namespace Juliet { InitializeLogManager(); MemoryArenasInit(); + + #ifdef JULIET_DEBUG + RunUnitTests(); + #endif + InitFilesystem(); JulietInit(flags); diff --git a/Juliet/src/UnitTest/Container/VectorUnitTest.cpp b/Juliet/src/UnitTest/Container/VectorUnitTest.cpp new file mode 100644 index 0000000..dc69046 --- /dev/null +++ b/Juliet/src/UnitTest/Container/VectorUnitTest.cpp @@ -0,0 +1,57 @@ +#ifdef JULIET_DEBUG + +#include +#include + +namespace Juliet +{ + void VectorUnitTest() + { + // Basic usage test + { + Vector vec; + Assert(vec.empty()); + Assert(vec.size() == 0); + + vec.push_back(10); + Assert(!vec.empty()); + Assert(vec.size() == 1); + Assert(vec[0] == 10); + + vec.push_back(20); + Assert(vec.size() == 2); + Assert(vec[1] == 20); + + // Test iteration (std::vector iterator compatibility) + int sum = 0; + for (int val : vec) + { + sum += val; + } + Assert(sum == 30); + + vec.clear(); + Assert(vec.empty()); + Assert(vec.size() == 0); + } + + // Test with complex types (std::string) to ensure proper construction/destruction + // Note: Vector.h currently inherits from std::vector, so this tests std::vector really. + { + struct TestStruct + { + int Value; + bool Active; + }; + + Vector structVec; + structVec.push_back({ 42, true }); + + Assert(structVec.size() == 1); + Assert(structVec[0].Value == 42); + Assert(structVec[0].Active == true); + } + } +} + +#endif \ No newline at end of file diff --git a/Juliet/src/UnitTest/RunUnitTests.cpp b/Juliet/src/UnitTest/RunUnitTests.cpp new file mode 100644 index 0000000..eb342c6 --- /dev/null +++ b/Juliet/src/UnitTest/RunUnitTests.cpp @@ -0,0 +1,23 @@ +#ifdef JULIET_DEBUG + +#include +#include +#include + + +namespace Juliet +{ + // Forward declare the VectorUnitTest function + void VectorUnitTest(); + + void RunUnitTests() + { + LogMessage(LogCategory::Core, "Starting Unit Tests..."); + + VectorUnitTest(); + + LogMessage(LogCategory::Core, "Unit Tests Completed Successfully."); + } +} + +#endif \ No newline at end of file