Improves test accuracy and adds .gitignore entry

Updates unit tests to include more accurate assertions for camera projections.

Adds .idea/workspace.xml to .gitignore to prevent tracking local IDE settings.

Refactors some test fixture class names for consistency.
This commit is contained in:
2025-08-21 00:30:05 +03:00
parent 625c676010
commit 83d3cc099f
6 changed files with 38 additions and 30 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
/out /out
*.DS_Store *.DS_Store
/extlibs/vcpkg /extlibs/vcpkg
.idea/workspace.xml

7
.idea/workspace.xml generated
View File

@@ -39,9 +39,10 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="24dcf302-ac9d-40e6-8317-7203a956ad63" name="Changes" comment=""> <list default="true" id="24dcf302-ac9d-40e6-8317-7203a956ad63" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" /> <change beforePath="$PROJECT_DIR$/tests/engines/unit_test_unity_engine.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/tests/engines/unit_test_unity_engine.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/include/omath/color.hpp" beforeDir="false" afterPath="$PROJECT_DIR$/include/omath/color.hpp" afterDir="false" /> <change beforePath="$PROJECT_DIR$/tests/general/unit_test_projection.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/tests/general/unit_test_projection.cpp" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -238,7 +239,7 @@
<workItem from="1752302256186" duration="714000" /> <workItem from="1752302256186" duration="714000" />
<workItem from="1753455801202" duration="1091000" /> <workItem from="1753455801202" duration="1091000" />
<workItem from="1755627102717" duration="301000" /> <workItem from="1755627102717" duration="301000" />
<workItem from="1755723773366" duration="852000" /> <workItem from="1755723773366" duration="1560000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@@ -88,7 +88,9 @@ TEST(unit_test_unity_engine, Project)
const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.03f, 1000.f); const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.03f, 1000.f);
const auto proj = cam.world_to_screen({5.f, 3, 10.f}); const auto proj = cam.world_to_screen({5.f, 3, 10.f});
std::println("{} {}", proj->x, proj->y);
EXPECT_NEAR(proj->x, 951.769f, 0.001f);
EXPECT_NEAR(proj->y, 547.061f, 0.001f);
} }
TEST(unit_test_unity_engine, CameraSetAndGetFov) TEST(unit_test_unity_engine, CameraSetAndGetFov)

View File

@@ -31,10 +31,10 @@ namespace
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Fixture with one canonical rightangled triangle in the XY plane. // Fixture with one canonical rightangled triangle in the XY plane.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class line_tracer_fixture : public ::testing::Test class LineTracerFixture : public ::testing::Test
{ {
protected: protected:
line_tracer_fixture() : LineTracerFixture() :
triangle({0.f, 0.f, 0.f}, {1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}) triangle({0.f, 0.f, 0.f}, {1.f, 0.f, 0.f}, {0.f, 1.f, 0.f})
{ {
} }
@@ -51,7 +51,7 @@ namespace
bool expected_clear; // true => segment does NOT hit the triangle bool expected_clear; // true => segment does NOT hit the triangle
}; };
class CanTraceLineParam : public line_tracer_fixture, class CanTraceLineParam : public LineTracerFixture,
public ::testing::WithParamInterface<TraceCase> public ::testing::WithParamInterface<TraceCase>
{ {
}; };
@@ -79,7 +79,7 @@ namespace
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Validate that the reported hit point is correct for a genuine intersection. // Validate that the reported hit point is correct for a genuine intersection.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST_F(line_tracer_fixture, HitPointCorrect) TEST_F(LineTracerFixture, HitPointCorrect)
{ {
constexpr Ray ray{{0.3f, 0.3f, -1.f}, {0.3f, 0.3f, 1.f}}; constexpr Ray ray{{0.3f, 0.3f, -1.f}, {0.3f, 0.3f, 1.f}};
constexpr Vec3 expected{0.3f, 0.3f, 0.f}; constexpr Vec3 expected{0.3f, 0.3f, 0.f};
@@ -92,7 +92,7 @@ namespace
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Triangle far beyond the ray should not block. // Triangle far beyond the ray should not block.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST_F(line_tracer_fixture, DistantTriangleClear) TEST_F(LineTracerFixture, DistantTriangleClear)
{ {
constexpr Ray short_ray{{0.f, 0.f, 0.f}, {0.f, 0.f, 1.f}}; constexpr Ray short_ray{{0.f, 0.f, 0.f}, {0.f, 0.f, 1.f}};
constexpr Triangle<Vec3> distant{{1000.f, 1000.f, 1000.f}, constexpr Triangle<Vec3> distant{{1000.f, 1000.f, 1000.f},

View File

@@ -5,7 +5,7 @@
using namespace omath; using namespace omath;
class unit_test_mat : public ::testing::Test class UnitTestMat : public ::testing::Test
{ {
protected: protected:
Mat<2, 2> m1; Mat<2, 2> m1;
@@ -19,7 +19,7 @@ protected:
}; };
// Test constructors // Test constructors
TEST_F(unit_test_mat, Constructor_Default) TEST_F(UnitTestMat, Constructor_Default)
{ {
Mat<3, 3> m; Mat<3, 3> m;
EXPECT_EQ(m.row_count(), 3); EXPECT_EQ(m.row_count(), 3);
@@ -29,7 +29,7 @@ TEST_F(unit_test_mat, Constructor_Default)
EXPECT_FLOAT_EQ(m.at(i, j), 0.0f); EXPECT_FLOAT_EQ(m.at(i, j), 0.0f);
} }
TEST_F(unit_test_mat, Constructor_InitializerList) TEST_F(UnitTestMat, Constructor_InitializerList)
{ {
constexpr Mat<2, 2> m{{1.0f, 2.0f}, {3.0f, 4.0f}}; constexpr Mat<2, 2> m{{1.0f, 2.0f}, {3.0f, 4.0f}};
EXPECT_EQ(m.row_count(), 2); EXPECT_EQ(m.row_count(), 2);
@@ -40,7 +40,7 @@ TEST_F(unit_test_mat, Constructor_InitializerList)
EXPECT_FLOAT_EQ(m.at(1, 1), 4.0f); EXPECT_FLOAT_EQ(m.at(1, 1), 4.0f);
} }
TEST_F(unit_test_mat, Operator_SquareBrackets) TEST_F(UnitTestMat, Operator_SquareBrackets)
{ {
EXPECT_EQ((m2[0, 0]), 1.0f); EXPECT_EQ((m2[0, 0]), 1.0f);
EXPECT_EQ((m2[0, 1]), 2.0f); EXPECT_EQ((m2[0, 1]), 2.0f);
@@ -48,7 +48,7 @@ TEST_F(unit_test_mat, Operator_SquareBrackets)
EXPECT_EQ((m2[1, 1]), 4.0f); EXPECT_EQ((m2[1, 1]), 4.0f);
} }
TEST_F(unit_test_mat, Constructor_Copy) TEST_F(UnitTestMat, Constructor_Copy)
{ {
Mat<2, 2> m3 = m2; Mat<2, 2> m3 = m2;
EXPECT_EQ(m3.row_count(), m2.row_count()); EXPECT_EQ(m3.row_count(), m2.row_count());
@@ -57,7 +57,7 @@ TEST_F(unit_test_mat, Constructor_Copy)
EXPECT_FLOAT_EQ(m3.at(1, 1), m2.at(1, 1)); EXPECT_FLOAT_EQ(m3.at(1, 1), m2.at(1, 1));
} }
TEST_F(unit_test_mat, Constructor_Move) TEST_F(UnitTestMat, Constructor_Move)
{ {
Mat<2, 2> m3 = std::move(m2); Mat<2, 2> m3 = std::move(m2);
EXPECT_EQ(m3.row_count(), 2); EXPECT_EQ(m3.row_count(), 2);
@@ -68,7 +68,7 @@ TEST_F(unit_test_mat, Constructor_Move)
} }
// Test matrix operations // Test matrix operations
TEST_F(unit_test_mat, Operator_Multiplication_Matrix) TEST_F(UnitTestMat, Operator_Multiplication_Matrix)
{ {
Mat<2, 2> m3 = m2 * m2; Mat<2, 2> m3 = m2 * m2;
EXPECT_EQ(m3.row_count(), 2); EXPECT_EQ(m3.row_count(), 2);
@@ -79,14 +79,14 @@ TEST_F(unit_test_mat, Operator_Multiplication_Matrix)
EXPECT_FLOAT_EQ(m3.at(1, 1), 22.0f); EXPECT_FLOAT_EQ(m3.at(1, 1), 22.0f);
} }
TEST_F(unit_test_mat, Operator_Multiplication_Scalar) TEST_F(UnitTestMat, Operator_Multiplication_Scalar)
{ {
Mat<2, 2> m3 = m2 * 2.0f; Mat<2, 2> m3 = m2 * 2.0f;
EXPECT_FLOAT_EQ(m3.at(0, 0), 2.0f); EXPECT_FLOAT_EQ(m3.at(0, 0), 2.0f);
EXPECT_FLOAT_EQ(m3.at(1, 1), 8.0f); EXPECT_FLOAT_EQ(m3.at(1, 1), 8.0f);
} }
TEST_F(unit_test_mat, Operator_Division_Scalar) TEST_F(UnitTestMat, Operator_Division_Scalar)
{ {
Mat<2, 2> m3 = m2 / 2.0f; Mat<2, 2> m3 = m2 / 2.0f;
EXPECT_FLOAT_EQ(m3.at(0, 0), 0.5f); EXPECT_FLOAT_EQ(m3.at(0, 0), 0.5f);
@@ -94,7 +94,7 @@ TEST_F(unit_test_mat, Operator_Division_Scalar)
} }
// Test matrix functions // Test matrix functions
TEST_F(unit_test_mat, Transpose) TEST_F(UnitTestMat, Transpose)
{ {
Mat<2, 2> m3 = m2.transposed(); Mat<2, 2> m3 = m2.transposed();
EXPECT_FLOAT_EQ(m3.at(0, 0), m2.at(0, 0)); EXPECT_FLOAT_EQ(m3.at(0, 0), m2.at(0, 0));
@@ -103,19 +103,19 @@ TEST_F(unit_test_mat, Transpose)
EXPECT_FLOAT_EQ(m3.at(1, 1), m2.at(1, 1)); EXPECT_FLOAT_EQ(m3.at(1, 1), m2.at(1, 1));
} }
TEST_F(unit_test_mat, Determinant) TEST_F(UnitTestMat, Determinant)
{ {
const float det = m2.determinant(); const float det = m2.determinant();
EXPECT_FLOAT_EQ(det, -2.0f); EXPECT_FLOAT_EQ(det, -2.0f);
} }
TEST_F(unit_test_mat, Sum) TEST_F(UnitTestMat, Sum)
{ {
const float sum = m2.sum(); const float sum = m2.sum();
EXPECT_FLOAT_EQ(sum, 10.0f); EXPECT_FLOAT_EQ(sum, 10.0f);
} }
TEST_F(unit_test_mat, Clear) TEST_F(UnitTestMat, Clear)
{ {
m2.clear(); m2.clear();
for (size_t i = 0; i < m2.row_count(); ++i) for (size_t i = 0; i < m2.row_count(); ++i)
@@ -123,7 +123,7 @@ TEST_F(unit_test_mat, Clear)
EXPECT_FLOAT_EQ(m2.at(i, j), 0.0f); EXPECT_FLOAT_EQ(m2.at(i, j), 0.0f);
} }
TEST_F(unit_test_mat, ToString) TEST_F(UnitTestMat, ToString)
{ {
const std::string str = m2.to_string(); const std::string str = m2.to_string();
EXPECT_FALSE(str.empty()); EXPECT_FALSE(str.empty());
@@ -131,7 +131,7 @@ TEST_F(unit_test_mat, ToString)
} }
// Test assignment operators // Test assignment operators
TEST_F(unit_test_mat, AssignmentOperator_Copy) TEST_F(UnitTestMat, AssignmentOperator_Copy)
{ {
Mat<2, 2> m3; Mat<2, 2> m3;
m3 = m2; m3 = m2;
@@ -140,7 +140,7 @@ TEST_F(unit_test_mat, AssignmentOperator_Copy)
EXPECT_FLOAT_EQ(m3.at(0, 0), m2.at(0, 0)); EXPECT_FLOAT_EQ(m3.at(0, 0), m2.at(0, 0));
} }
TEST_F(unit_test_mat, AssignmentOperator_Move) TEST_F(UnitTestMat, AssignmentOperator_Move)
{ {
Mat<2, 2> m3; Mat<2, 2> m3;
m3 = std::move(m2); m3 = std::move(m2);
@@ -152,7 +152,7 @@ TEST_F(unit_test_mat, AssignmentOperator_Move)
} }
// Test static methods // Test static methods
TEST_F(unit_test_mat, StaticMethod_ToScreenMat) TEST_F(UnitTestMat, StaticMethod_ToScreenMat)
{ {
Mat<4, 4> screenMat = Mat<4, 4>::to_screen_mat(800.0f, 600.0f); Mat<4, 4> screenMat = Mat<4, 4>::to_screen_mat(800.0f, 600.0f);
EXPECT_FLOAT_EQ(screenMat.at(0, 0), 400.0f); EXPECT_FLOAT_EQ(screenMat.at(0, 0), 400.0f);
@@ -164,7 +164,7 @@ TEST_F(unit_test_mat, StaticMethod_ToScreenMat)
// Test exception handling in At() method // Test exception handling in At() method
TEST_F(unit_test_mat, Method_At_OutOfRange) TEST_F(UnitTestMat, Method_At_OutOfRange)
{ {
#if !defined(NDEBUG) && defined(OMATH_SUPRESS_SAFETY_CHECKS) #if !defined(NDEBUG) && defined(OMATH_SUPRESS_SAFETY_CHECKS)
EXPECT_THROW(std::ignore = m2.at(2, 0), std::out_of_range); EXPECT_THROW(std::ignore = m2.at(2, 0), std::out_of_range);

View File

@@ -9,9 +9,13 @@
TEST(UnitTestProjection, Projection) TEST(UnitTestProjection, Projection)
{ {
const auto x = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f); constexpr auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, x, 0.01f, 1000.f); const auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov,
0.01f, 1000.f);
const auto projected = cam.world_to_screen({1000, 0, 50}); const auto projected = cam.world_to_screen({1000, 0, 50});
std::print("{} {} {}", projected->x, projected->y, projected->z);
EXPECT_NEAR(projected->x, 960.f, 0.001f);
EXPECT_NEAR(projected->y, 504.f, 0.001f);
EXPECT_NEAR(projected->z, 1.f, 0.001f);
} }