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:
@@ -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);
|
||||
|
||||
57
Juliet/src/UnitTest/Container/VectorUnitTest.cpp
Normal file
57
Juliet/src/UnitTest/Container/VectorUnitTest.cpp
Normal 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
|
||||
23
Juliet/src/UnitTest/RunUnitTests.cpp
Normal file
23
Juliet/src/UnitTest/RunUnitTests.cpp
Normal 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
|
||||
Reference in New Issue
Block a user