Add simple UnitTest that tests AABB_Box collision
This commit is contained in:
parent
3664e1734b
commit
9a5634f0da
2 changed files with 114 additions and 0 deletions
|
@ -36,3 +36,30 @@ $<IF:$<CONFIG:Debug>,-Og,-fno-delete-null-pointer-checks -fno-strict-overflow -f
|
|||
-Wl,-z,relro -Wl,-z,now
|
||||
-fPIC
|
||||
)
|
||||
|
||||
add_executable(UnitTest src/test.cpp)
|
||||
target_link_libraries(UnitTest SC_SeparatingAxisCollisionDetection)
|
||||
target_include_directories(UnitTest PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
target_compile_options(UnitTest PUBLIC
|
||||
$<IF:$<CONFIG:Debug>,-Og,-fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing -ftrivial-auto-var-init=zero>
|
||||
-Wall -Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough
|
||||
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3
|
||||
-D_GLIBCXX_ASSERTIONS
|
||||
-fstrict-flex-arrays=3
|
||||
-fstack-clash-protection -fstack-protector-strong
|
||||
-fPIE
|
||||
)
|
||||
|
||||
target_link_options(UnitTest PUBLIC
|
||||
$<IF:$<CONFIG:Debug>,-Og,-fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing -ftrivial-auto-var-init=zero>
|
||||
-Wall -Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough
|
||||
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3
|
||||
-D_GLIBCXX_ASSERTIONS
|
||||
-fstrict-flex-arrays=3
|
||||
-fstack-clash-protection -fstack-protector-strong
|
||||
-Wl,-z,nodlopen -Wl,-z,noexecstack
|
||||
-Wl,-z,relro -Wl,-z,now
|
||||
-fPIE
|
||||
-pie
|
||||
)
|
||||
|
|
87
src/test.cpp
Normal file
87
src/test.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include <iostream>
|
||||
|
||||
static int checks_checked = 0;
|
||||
static int checks_passed = 0;
|
||||
|
||||
// Macros for unit testing.
|
||||
|
||||
#define CHECK_TRUE(x) \
|
||||
do { \
|
||||
++checks_checked; \
|
||||
if (!(x)) { \
|
||||
std::cout << "CHECK_TRUE at line " << __LINE__ << " failed!\n"; \
|
||||
} else { \
|
||||
++checks_passed; \
|
||||
} \
|
||||
} while (false);
|
||||
#define CHECK_FALSE(x) \
|
||||
do { \
|
||||
++checks_checked; \
|
||||
if (x) { \
|
||||
std::cout << "CHECK_FALSE at line " << __LINE__ << " failed!\n"; \
|
||||
} else { \
|
||||
++checks_passed; \
|
||||
} \
|
||||
} while (false);
|
||||
|
||||
#include "sd_sacd.h"
|
||||
|
||||
int main() {
|
||||
// Test 2D AABB.
|
||||
SC_SACD_AABB_Box a{0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F};
|
||||
SC_SACD_AABB_Box b{2.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F};
|
||||
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.x = -2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.x = 0.5F;
|
||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
b.x = -0.5F;
|
||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.x = 0.0F;
|
||||
b.y = 2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
b.y = -2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.y = 0.5F;
|
||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
b.y = -0.5F;
|
||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.y = 0.0F;
|
||||
b.z = 2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.z = -2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.z = 0.5F;
|
||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.z = -0.5F;
|
||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.z = 0.0F;
|
||||
b.x = 0.5F;
|
||||
b.y = 2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.y = -2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.x = -0.5F;
|
||||
b.y = 2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
b.y = -2.0F;
|
||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
||||
|
||||
std::cout << "Checks checked: " << checks_checked << '\n'
|
||||
<< "Checks passed: " << checks_passed << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue