Batman
This commit is contained in:
48
project/tests/CMakeLists.txt
Normal file
48
project/tests/CMakeLists.txt
Normal file
@@ -0,0 +1,48 @@
|
||||
include(FetchContent)
|
||||
|
||||
# add gtest
|
||||
FetchContent_Declare(
|
||||
gtest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG v1.14.0
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
|
||||
set(BUILD_GTEST ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(gtest)
|
||||
|
||||
|
||||
# add source files
|
||||
set(SOURCES
|
||||
"../src/Matrix.cpp"
|
||||
"../src/Renderer.cpp"
|
||||
"../src/Scene.cpp"
|
||||
"../src/Timer.cpp"
|
||||
"../src/Vector3.cpp"
|
||||
"../src/Vector4.cpp"
|
||||
)
|
||||
|
||||
# add test source files
|
||||
set(TESTS
|
||||
"UnitTests.cpp"
|
||||
)
|
||||
|
||||
|
||||
# include SDL because camera class needs it
|
||||
set(SDL_DIR "${CMAKE_SOURCE_DIR}/project/libs/SDL2-2.30.3")
|
||||
add_library(SDL STATIC IMPORTED)
|
||||
set_target_properties(SDL PROPERTIES
|
||||
IMPORTED_LOCATION "${SDL_DIR}/lib/SDL2.lib"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${SDL_DIR}/include"
|
||||
)
|
||||
|
||||
|
||||
add_executable(UnitTests ${SOURCES} ${TESTS})
|
||||
target_link_libraries(UnitTests gtest gtest_main SDL)
|
||||
|
||||
# only needed if header files are not in same directory as source files
|
||||
# target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# add unit tests for test runner to discover
|
||||
add_test(NAME UnitTests COMMAND UnitTests)
|
||||
44
project/tests/UnitTests.cpp
Normal file
44
project/tests/UnitTests.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "../src/Vector3.h"
|
||||
#include "../src/Vector4.h"
|
||||
#include "../src/Matrix.h"
|
||||
|
||||
namespace dae
|
||||
{
|
||||
// W1
|
||||
TEST(Vector3, DotProduct) {
|
||||
EXPECT_EQ(1.0f, Vector3::Dot(Vector3::UnitX, Vector3::UnitX)); // (1) Same direction
|
||||
EXPECT_EQ(-1.0f, Vector3::Dot(Vector3::UnitX, -Vector3::UnitX)); // (-1) Opposite direction
|
||||
EXPECT_EQ(0.0f, Vector3::Dot(Vector3::UnitX, Vector3::UnitY)); // (0) Perpendicular
|
||||
|
||||
Vector3 v1(1.0f, 2.0f, 3.0f);
|
||||
Vector3 v2(4.0f, 5.0f, 6.0f);
|
||||
EXPECT_EQ(32.0f, dae::Vector3::Dot(v1, v2));
|
||||
}
|
||||
|
||||
// W1
|
||||
TEST(Vector4, DotProduct) {
|
||||
EXPECT_EQ(70.f, Vector4::Dot({ 1, 2, 3, 4 }, { 5, 6, 7, 8 }));
|
||||
EXPECT_EQ(30.f, Vector4::Dot({ 1, 2, 3, 4 }, { 1, 2, 3, 4 }));
|
||||
EXPECT_EQ(-30.f, Vector4::Dot({ 1, 2, 3, 4 }, { -1, -2, -3, -4 }));
|
||||
EXPECT_EQ(0.f, Vector4::Dot({ 1, 0, 0, 0 }, { 0, 1, 0, 0 }));
|
||||
EXPECT_EQ(0.f, Vector4::Dot({ 0, 1, 0, 0 }, { 0, 0, 1, 0 }));
|
||||
}
|
||||
|
||||
// W1
|
||||
TEST(Vector3, CrossProduct) {
|
||||
EXPECT_EQ(Vector3::UnitY, Vector3::Cross(Vector3::UnitZ, Vector3::UnitX)); // (0,1,0) UnitY
|
||||
EXPECT_EQ(-Vector3::UnitY, Vector3::Cross(Vector3::UnitX, Vector3::UnitZ)); // (0,-1,0) -UnitY
|
||||
|
||||
Vector3 v1(1.0f, 2.0f, 3.0f);
|
||||
Vector3 v2(4.0f, 5.0f, 6.0f);
|
||||
EXPECT_EQ(dae::Vector3(-3.0f, 6.0f, -3.0f), dae::Vector3::Cross(v1, v2));
|
||||
}
|
||||
|
||||
// W1
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user