From 83d3cc099f48e285141b0c9e79d4c5e672ea7a36 Mon Sep 17 00:00:00 2001 From: Orange Date: Thu, 21 Aug 2025 00:30:05 +0300 Subject: [PATCH] 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. --- .gitignore | 1 + .idea/workspace.xml | 7 +++-- tests/engines/unit_test_unity_engine.cpp | 4 ++- tests/general/unit_test_line_trace.cpp | 10 +++---- tests/general/unit_test_mat.cpp | 36 ++++++++++++------------ tests/general/unit_test_projection.cpp | 10 +++++-- 6 files changed, 38 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 8d0081d..97394d7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /out *.DS_Store /extlibs/vcpkg +.idea/workspace.xml \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1c34a9f..63c3bb6 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -39,9 +39,10 @@ + - - + + diff --git a/tests/engines/unit_test_unity_engine.cpp b/tests/engines/unit_test_unity_engine.cpp index 2baac70..47ce136 100644 --- a/tests/engines/unit_test_unity_engine.cpp +++ b/tests/engines/unit_test_unity_engine.cpp @@ -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 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) diff --git a/tests/general/unit_test_line_trace.cpp b/tests/general/unit_test_line_trace.cpp index 3f0e1d6..89167bd 100644 --- a/tests/general/unit_test_line_trace.cpp +++ b/tests/general/unit_test_line_trace.cpp @@ -31,10 +31,10 @@ namespace // ----------------------------------------------------------------------------- // Fixture with one canonical right‑angled triangle in the XY plane. // ----------------------------------------------------------------------------- - class line_tracer_fixture : public ::testing::Test + class LineTracerFixture : public ::testing::Test { protected: - line_tracer_fixture() : + LineTracerFixture() : 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 }; - class CanTraceLineParam : public line_tracer_fixture, + class CanTraceLineParam : public LineTracerFixture, public ::testing::WithParamInterface { }; @@ -79,7 +79,7 @@ namespace // ----------------------------------------------------------------------------- // 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 Vec3 expected{0.3f, 0.3f, 0.f}; @@ -92,7 +92,7 @@ namespace // ----------------------------------------------------------------------------- // 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 Triangle distant{{1000.f, 1000.f, 1000.f}, diff --git a/tests/general/unit_test_mat.cpp b/tests/general/unit_test_mat.cpp index de2c698..9bae411 100644 --- a/tests/general/unit_test_mat.cpp +++ b/tests/general/unit_test_mat.cpp @@ -5,7 +5,7 @@ using namespace omath; -class unit_test_mat : public ::testing::Test +class UnitTestMat : public ::testing::Test { protected: Mat<2, 2> m1; @@ -19,7 +19,7 @@ protected: }; // Test constructors -TEST_F(unit_test_mat, Constructor_Default) +TEST_F(UnitTestMat, Constructor_Default) { Mat<3, 3> m; 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); } -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}}; 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); } -TEST_F(unit_test_mat, Operator_SquareBrackets) +TEST_F(UnitTestMat, Operator_SquareBrackets) { EXPECT_EQ((m2[0, 0]), 1.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); } -TEST_F(unit_test_mat, Constructor_Copy) +TEST_F(UnitTestMat, Constructor_Copy) { Mat<2, 2> m3 = m2; 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)); } -TEST_F(unit_test_mat, Constructor_Move) +TEST_F(UnitTestMat, Constructor_Move) { Mat<2, 2> m3 = std::move(m2); EXPECT_EQ(m3.row_count(), 2); @@ -68,7 +68,7 @@ TEST_F(unit_test_mat, Constructor_Move) } // Test matrix operations -TEST_F(unit_test_mat, Operator_Multiplication_Matrix) +TEST_F(UnitTestMat, Operator_Multiplication_Matrix) { Mat<2, 2> m3 = m2 * m2; 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); } -TEST_F(unit_test_mat, Operator_Multiplication_Scalar) +TEST_F(UnitTestMat, Operator_Multiplication_Scalar) { Mat<2, 2> m3 = m2 * 2.0f; EXPECT_FLOAT_EQ(m3.at(0, 0), 2.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; 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_F(unit_test_mat, Transpose) +TEST_F(UnitTestMat, Transpose) { Mat<2, 2> m3 = m2.transposed(); 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)); } -TEST_F(unit_test_mat, Determinant) +TEST_F(UnitTestMat, Determinant) { const float det = m2.determinant(); EXPECT_FLOAT_EQ(det, -2.0f); } -TEST_F(unit_test_mat, Sum) +TEST_F(UnitTestMat, Sum) { const float sum = m2.sum(); EXPECT_FLOAT_EQ(sum, 10.0f); } -TEST_F(unit_test_mat, Clear) +TEST_F(UnitTestMat, Clear) { m2.clear(); 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); } -TEST_F(unit_test_mat, ToString) +TEST_F(UnitTestMat, ToString) { const std::string str = m2.to_string(); EXPECT_FALSE(str.empty()); @@ -131,7 +131,7 @@ TEST_F(unit_test_mat, ToString) } // Test assignment operators -TEST_F(unit_test_mat, AssignmentOperator_Copy) +TEST_F(UnitTestMat, AssignmentOperator_Copy) { Mat<2, 2> m3; m3 = m2; @@ -140,7 +140,7 @@ TEST_F(unit_test_mat, AssignmentOperator_Copy) 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; m3 = std::move(m2); @@ -152,7 +152,7 @@ TEST_F(unit_test_mat, AssignmentOperator_Move) } // 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); 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_F(unit_test_mat, Method_At_OutOfRange) +TEST_F(UnitTestMat, Method_At_OutOfRange) { #if !defined(NDEBUG) && defined(OMATH_SUPRESS_SAFETY_CHECKS) EXPECT_THROW(std::ignore = m2.at(2, 0), std::out_of_range); diff --git a/tests/general/unit_test_projection.cpp b/tests/general/unit_test_projection.cpp index ac4892a..a5ca9a7 100644 --- a/tests/general/unit_test_projection.cpp +++ b/tests/general/unit_test_projection.cpp @@ -9,9 +9,13 @@ TEST(UnitTestProjection, Projection) { - const auto x = omath::Angle::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); + constexpr auto fov = omath::Angle::from_degrees(90.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}); - 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); } \ No newline at end of file