Fixed broken unit tests
This commit is contained in:
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@@ -8,7 +8,7 @@
|
|||||||
"name": "Debug Matrix Unit Tests",
|
"name": "Debug Matrix Unit Tests",
|
||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/build/src/Matrix/matrix-tests",
|
"program": "${workspaceFolder}/build/unit-tests/matrix-tests",
|
||||||
"args": [],
|
"args": [],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
"name": "Debug Quaternion Unit Tests",
|
"name": "Debug Quaternion Unit Tests",
|
||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/build/src/Quaternion/quaternion-tests",
|
"program": "${workspaceFolder}/build/unit-tests/quaternion-tests",
|
||||||
"args": [],
|
"args": [],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ cmake_minimum_required (VERSION 3.11)
|
|||||||
project(Vector3D)
|
project(Vector3D)
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
add_subdirectory(unit-tests)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
# Quaternion tests
|
# Quaternion tests
|
||||||
add_executable(quaternion-tests unit-tests/quaternion-tests.cpp)
|
add_executable(quaternion-tests quaternion-tests.cpp)
|
||||||
|
|
||||||
target_link_libraries(quaternion-tests
|
target_link_libraries(quaternion-tests
|
||||||
PRIVATE
|
PRIVATE
|
||||||
vector-3d-intf
|
quaternion
|
||||||
Catch2::Catch2WithMain
|
Catch2::Catch2WithMain
|
||||||
)
|
)
|
||||||
|
|
||||||
# matrix tests
|
# matrix tests
|
||||||
add_executable(matrix-tests unit-tests/matrix-tests.cpp)
|
add_executable(matrix-tests matrix-tests.cpp)
|
||||||
|
|
||||||
target_link_libraries(matrix-tests
|
target_link_libraries(matrix-tests
|
||||||
PRIVATE
|
PRIVATE
|
||||||
vector-3d-intf
|
matrix
|
||||||
Catch2::Catch2WithMain
|
Catch2::Catch2WithMain
|
||||||
)
|
)
|
||||||
|
|
||||||
# Vector 3D Tests
|
# Vector 3D Tests
|
||||||
add_executable(vector-3d-tests unit-tests/vector-tests.cpp)
|
add_executable(vector-3d-tests vector-tests.cpp)
|
||||||
|
|
||||||
target_link_libraries(vector-3d-tests
|
target_link_libraries(vector-3d-tests
|
||||||
PRIVATE
|
PRIVATE
|
||||||
vector-3d-intf
|
vector-3d
|
||||||
Catch2::Catch2WithMain
|
Catch2::Catch2WithMain
|
||||||
)
|
)
|
||||||
@@ -240,7 +240,7 @@ TEST_CASE("Elementary Matrix Operations", "Matrix")
|
|||||||
|
|
||||||
SECTION("Invert")
|
SECTION("Invert")
|
||||||
{
|
{
|
||||||
mat1.Invert(mat3);
|
mat3 = mat1.Invert();
|
||||||
REQUIRE_THAT(mat3.Get(0, 0), Catch::Matchers::WithinRel(-2.0F, 1e-6f));
|
REQUIRE_THAT(mat3.Get(0, 0), Catch::Matchers::WithinRel(-2.0F, 1e-6f));
|
||||||
REQUIRE_THAT(mat3.Get(0, 1), Catch::Matchers::WithinRel(1.0F, 1e-6f));
|
REQUIRE_THAT(mat3.Get(0, 1), Catch::Matchers::WithinRel(1.0F, 1e-6f));
|
||||||
REQUIRE_THAT(mat3.Get(1, 0), Catch::Matchers::WithinRel(1.5F, 1e-6f));
|
REQUIRE_THAT(mat3.Get(1, 0), Catch::Matchers::WithinRel(1.5F, 1e-6f));
|
||||||
@@ -250,7 +250,7 @@ TEST_CASE("Elementary Matrix Operations", "Matrix")
|
|||||||
SECTION("Transpose")
|
SECTION("Transpose")
|
||||||
{
|
{
|
||||||
// transpose a square matrix
|
// transpose a square matrix
|
||||||
mat1.Transpose(mat3);
|
mat3 = mat1.Transpose();
|
||||||
|
|
||||||
REQUIRE(mat3.Get(0, 0) == 1);
|
REQUIRE(mat3.Get(0, 0) == 1);
|
||||||
REQUIRE(mat3.Get(0, 1) == 3);
|
REQUIRE(mat3.Get(0, 1) == 3);
|
||||||
@@ -261,7 +261,7 @@ TEST_CASE("Elementary Matrix Operations", "Matrix")
|
|||||||
Matrix<2, 3> mat4{1, 2, 3, 4, 5, 6};
|
Matrix<2, 3> mat4{1, 2, 3, 4, 5, 6};
|
||||||
Matrix<3, 2> mat5{};
|
Matrix<3, 2> mat5{};
|
||||||
|
|
||||||
mat4.Transpose(mat5);
|
mat5 = mat4.Transpose();
|
||||||
|
|
||||||
REQUIRE(mat5.Get(0, 0) == 1);
|
REQUIRE(mat5.Get(0, 0) == 1);
|
||||||
REQUIRE(mat5.Get(0, 1) == 4);
|
REQUIRE(mat5.Get(0, 1) == 4);
|
||||||
@@ -315,6 +315,75 @@ TEST_CASE("Elementary Matrix Operations", "Matrix")
|
|||||||
REQUIRE(mat1Columns.Get(0, 0) == 2);
|
REQUIRE(mat1Columns.Get(0, 0) == 2);
|
||||||
REQUIRE(mat1Columns.Get(1, 0) == 4);
|
REQUIRE(mat1Columns.Get(1, 0) == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("Get Sub-Matrices")
|
||||||
|
{
|
||||||
|
Matrix<3, 3> mat4{
|
||||||
|
1, 2, 3,
|
||||||
|
4, 5, 6,
|
||||||
|
7, 8, 9};
|
||||||
|
|
||||||
|
Matrix<2, 2> mat5{0};
|
||||||
|
|
||||||
|
mat4.SubMatrix(mat5, 0, 0);
|
||||||
|
REQUIRE(mat5.Get(0, 0) == 1);
|
||||||
|
REQUIRE(mat5.Get(0, 1) == 2);
|
||||||
|
REQUIRE(mat5.Get(1, 0) == 4);
|
||||||
|
REQUIRE(mat5.Get(1, 1) == 5);
|
||||||
|
|
||||||
|
mat4.SubMatrix(mat5, 1, 1);
|
||||||
|
REQUIRE(mat5.Get(0, 0) == 5);
|
||||||
|
REQUIRE(mat5.Get(0, 1) == 6);
|
||||||
|
REQUIRE(mat5.Get(1, 0) == 8);
|
||||||
|
REQUIRE(mat5.Get(1, 1) == 9);
|
||||||
|
|
||||||
|
Matrix<3, 1> mat6{0};
|
||||||
|
mat4.SubMatrix(mat6, 0, 0);
|
||||||
|
REQUIRE(mat6.Get(0, 0) == 1);
|
||||||
|
REQUIRE(mat6.Get(1, 0) == 4);
|
||||||
|
REQUIRE(mat6.Get(2, 0) == 7);
|
||||||
|
|
||||||
|
Matrix<1, 3> mat7{0};
|
||||||
|
mat4.SubMatrix(mat7, 0, 0);
|
||||||
|
REQUIRE(mat7.Get(0, 0) == 1);
|
||||||
|
REQUIRE(mat7.Get(0, 1) == 2);
|
||||||
|
REQUIRE(mat7.Get(0, 2) == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Set Sub-Matrices")
|
||||||
|
{
|
||||||
|
Matrix<3, 3> startMatrix{
|
||||||
|
1, 2, 3,
|
||||||
|
4, 5, 6,
|
||||||
|
7, 8, 9};
|
||||||
|
Matrix<3, 3> mat4 = startMatrix;
|
||||||
|
|
||||||
|
Matrix<2, 2> mat5{10, 11, 12, 13};
|
||||||
|
mat4.SetSubMatrix(mat5, 0, 0);
|
||||||
|
REQUIRE(mat4.Get(0, 0) == 10);
|
||||||
|
REQUIRE(mat4.Get(0, 1) == 11);
|
||||||
|
REQUIRE(mat4.Get(1, 0) == 12);
|
||||||
|
REQUIRE(mat4.Get(1, 1) == 13);
|
||||||
|
|
||||||
|
mat4 = startMatrix;
|
||||||
|
mat4.SetSubMatrix(mat5, 1, 1);
|
||||||
|
REQUIRE(mat4.Get(1, 1) == 10);
|
||||||
|
REQUIRE(mat4.Get(1, 2) == 11);
|
||||||
|
REQUIRE(mat4.Get(2, 1) == 12);
|
||||||
|
REQUIRE(mat4.Get(2, 2) == 13);
|
||||||
|
|
||||||
|
Matrix<3, 1> mat6{10, 11, 12};
|
||||||
|
mat4.SetSubMatrix(mat6, 0, 0);
|
||||||
|
REQUIRE(mat4.Get(0, 0) == 10);
|
||||||
|
REQUIRE(mat4.Get(1, 0) == 11);
|
||||||
|
REQUIRE(mat4.Get(2, 0) == 12);
|
||||||
|
|
||||||
|
Matrix<1, 3> mat7{10, 11, 12};
|
||||||
|
mat4.SetSubMatrix(mat7, 0, 0);
|
||||||
|
REQUIRE(mat4.Get(0, 0) == 10);
|
||||||
|
REQUIRE(mat4.Get(0, 1) == 11);
|
||||||
|
REQUIRE(mat4.Get(0, 2) == 12);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// basically re-run all of the previous tests with huge matrices and time the
|
// basically re-run all of the previous tests with huge matrices and time the
|
||||||
@@ -418,7 +487,7 @@ TEST_CASE("Timing Tests", "Matrix")
|
|||||||
{
|
{
|
||||||
for (uint32_t i{0}; i < 100000; i++)
|
for (uint32_t i{0}; i < 100000; i++)
|
||||||
{
|
{
|
||||||
mat4.Invert(mat5);
|
mat5 = mat4.Invert();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -426,7 +495,7 @@ TEST_CASE("Timing Tests", "Matrix")
|
|||||||
{
|
{
|
||||||
for (uint32_t i{0}; i < 10000; i++)
|
for (uint32_t i{0}; i < 10000; i++)
|
||||||
{
|
{
|
||||||
mat1.Transpose(mat3);
|
mat3 = mat1.Transpose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user