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
This commit is contained in:
2026-02-07 18:22:45 -05:00
parent 84fe295e18
commit 6f4fc75b66
3 changed files with 89 additions and 0 deletions

View File

@@ -17,6 +17,10 @@
namespace Juliet namespace Juliet
{ {
#ifdef JULIET_DEBUG
extern void RunUnitTests();
#endif
namespace namespace
{ {
Engine EngineInstance; Engine EngineInstance;
@@ -131,6 +135,11 @@ namespace Juliet
{ {
InitializeLogManager(); InitializeLogManager();
MemoryArenasInit(); MemoryArenasInit();
#ifdef JULIET_DEBUG
RunUnitTests();
#endif
InitFilesystem(); InitFilesystem();
JulietInit(flags); JulietInit(flags);

View File

@@ -0,0 +1,57 @@
#ifdef JULIET_DEBUG
#include <Core/Container/Vector.h>
#include <Core/Common/CoreUtils.h>
namespace Juliet
{
void VectorUnitTest()
{
// Basic usage test
{
Vector<int> 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<TestStruct> structVec;
structVec.push_back({ 42, true });
Assert(structVec.size() == 1);
Assert(structVec[0].Value == 42);
Assert(structVec[0].Active == true);
}
}
}
#endif

View File

@@ -0,0 +1,23 @@
#ifdef JULIET_DEBUG
#include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h>
#include <Core/Common/CoreUtils.h>
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