diff --git a/tests/src/Base/CMakeLists.txt b/tests/src/Base/CMakeLists.txt index 3e104cc952..0c4bb186da 100644 --- a/tests/src/Base/CMakeLists.txt +++ b/tests/src/Base/CMakeLists.txt @@ -1,6 +1,8 @@ target_sources( Tests_run PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Matrix.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Rotation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tst_Tools.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Units.cpp ) diff --git a/tests/src/Base/Matrix.cpp b/tests/src/Base/Matrix.cpp new file mode 100644 index 0000000000..8a9f76ae60 --- /dev/null +++ b/tests/src/Base/Matrix.cpp @@ -0,0 +1,123 @@ +#include "gtest/gtest.h" +#include + + +TEST(Matrix, TestShearing) +{ + Base::Matrix4D mat; + mat.setRow(1, Base::Vector3d(0, 1, 1)); + EXPECT_EQ(mat.hasScale(), Base::ScaleType::Other); +} + +TEST(Matrix, TestMultLeftRight) +{ + Base::Matrix4D mat1; + mat1.rotX(1.0); + Base::Matrix4D mat2; + mat2.scale(1.0, 2.0, 3.0); + EXPECT_EQ((mat1 * mat2).hasScale(), Base::ScaleType::NonUniformRight); + EXPECT_EQ((mat2 * mat1).hasScale(), Base::ScaleType::NonUniformLeft); +} + +TEST(Matrix, TestNoScale) +{ + Base::Matrix4D mat; + mat.rotX(1.0); + mat.scale(1.0); + EXPECT_EQ(mat.hasScale(), Base::ScaleType::NoScaling); +} + +TEST(Matrix, TestUniformScalePlusTwo) +{ + Base::Matrix4D mat; + mat.rotX(1.0); + mat.scale(2.0); + EXPECT_EQ(mat.hasScale(), Base::ScaleType::Uniform); +} + +TEST(Matrix, TestUniformScaleRight) +{ + Base::Matrix4D mat; + mat.rotX(1.0); + Base::Matrix4D scale; + scale.scale(2.0); + mat = mat * scale; + EXPECT_EQ(mat.hasScale(), Base::ScaleType::Uniform); +} + +TEST(Matrix, TestNonUniformScaleRight) +{ + Base::Matrix4D mat; + mat.rotX(1.0); + Base::Matrix4D scale; + scale.scale(2.0, 1.0, 2.0); + mat = mat * scale; + EXPECT_EQ(mat.hasScale(), Base::ScaleType::NonUniformRight); +} + +TEST(Matrix, TestUniformScaleMinusOne) +{ + Base::Matrix4D mat; + mat.scale(-1.0); + EXPECT_EQ(mat.hasScale(), Base::ScaleType::Uniform); +} + +TEST(Matrix, TestUniformScaleMinusTwo) +{ + Base::Matrix4D mat; + mat.scale(-2.0); + EXPECT_EQ(mat.hasScale(), Base::ScaleType::Uniform); +} + +TEST(Matrix, TestNonUniformScaleLeftOne) +{ + Base::Matrix4D mat; + mat.rotX(1.0); + mat.scale(1.0, -1.0, 1.0); + // A scale(1,-1,1) is like scale(-1,-1,-1) * rotation + EXPECT_EQ(mat.hasScale(), Base::ScaleType::Uniform); +} + +TEST(Matrix, TestNonUniformScaleLeftTwo) +{ + Base::Matrix4D mat; + mat.rotX(1.0); + mat.scale(2.0, -2.0, 2.0); + EXPECT_EQ(mat.hasScale(), Base::ScaleType::Uniform); +} + +TEST(Matrix, TestTrace) +{ + Base::Matrix4D mat; + mat.scale(2.0, 2.0, 2.0); + Base::Vector3d trace = mat.trace(); + EXPECT_EQ(trace.x + trace.y + trace.z, 6.0); +} + +TEST(Matrix, TestColRow) +{ + Base::Matrix4D mat; + EXPECT_EQ(mat.getCol(1), Base::Vector3d(0, 1, 0)); + EXPECT_EQ(mat.getCol(2), Base::Vector3d(0, 0, 1)); +} + +TEST(Matrix, TestUnity) +{ + Base::Matrix4D mat; + EXPECT_EQ(mat.isUnity(), true); + + mat.nullify(); + EXPECT_EQ(mat.isUnity(), false); + + mat.setToUnity(); + EXPECT_EQ(mat.isUnity(), true); +} + +TEST(Matrix, TestNull) +{ + Base::Matrix4D mat; + EXPECT_EQ(mat.isNull(), false); + + mat.nullify(); + EXPECT_EQ(mat.isNull(), true); +} diff --git a/tests/src/Base/Rotation.cpp b/tests/src/Base/Rotation.cpp new file mode 100644 index 0000000000..bf072dc736 --- /dev/null +++ b/tests/src/Base/Rotation.cpp @@ -0,0 +1,65 @@ +#include "gtest/gtest.h" +#include +#include + + +TEST(Rotation, TestNonUniformScaleLeft) +{ + Base::Rotation rot; + rot.setYawPitchRoll(20.0, 0.0, 0.0); + + Base::Matrix4D mat; + rot.getValue(mat); + + Base::Matrix4D scale; + scale.scale(2.0, 3.0, 4.0); + + Base::Rotation scaled_rot(scale * mat); + + EXPECT_EQ(scaled_rot.isSame(rot, 1.0e-7), true); + EXPECT_EQ(rot.isSame(scaled_rot, 1.0e-7), true); +} + +TEST(Rotation, TestNonUniformScaleRight) +{ + Base::Rotation rot; + rot.setYawPitchRoll(20.0, 0.0, 0.0); + + Base::Matrix4D mat; + rot.getValue(mat); + + Base::Matrix4D scale; + scale.scale(2.0, 3.0, 4.0); + + Base::Rotation scaled_rot(mat * scale); + + EXPECT_EQ(scaled_rot.isSame(rot, 1.0e-7), true); + EXPECT_EQ(rot.isSame(scaled_rot, 1.0e-7), true); +} + +TEST(Rotation, TestUniformScaleGT1) +{ + Base::Rotation rot; + rot.setYawPitchRoll(20.0, 0.0, 0.0); + + Base::Matrix4D mat; + rot.getValue(mat); + + Base::Matrix4D scale; + scale.scale(3.0, 3.0, 3.0); + + Base::Rotation scaled_rot(mat * scale); + + EXPECT_EQ(scaled_rot.isSame(rot, 1.0e-7), true); + EXPECT_EQ(rot.isSame(scaled_rot, 1.0e-7), true); +} + +TEST(Rotation, TestUniformScaleLT1) +{ + Base::Matrix4D mat; + mat.scale(0.5); + + Base::Rotation scaled_rot(mat); + + EXPECT_EQ(scaled_rot.isSame(scaled_rot, 1.0e-7), true); +}