Skip to content

Commit 2ab3682

Browse files
authored
Organize Tests Source (#70)
* Organize test sources * Add test config.hpp
1 parent 5851956 commit 2ab3682

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+836
-776
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ python/bunny.obj
260260
IPCToolkitOptions.cmake
261261

262262
src/ipc/config.hpp
263+
tests/src/tests/config.hpp
263264

264265
docs/_doxygen
265266

CMakeLists.txt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,9 @@ option(IPC_TOOLKIT_WITH_CUDA "Enable CUDA CCD"
6969
option(IPC_TOOLKIT_WITH_RATIONAL_INTERSECTION "Use rational edge-triangle intersection check" OFF)
7070
option(IPC_TOOLKIT_WITH_ROBIN_MAP "Use Tessil's robin-map rather than std maps" ON)
7171
option(IPC_TOOLKIT_WITH_ABSEIL "Use Abseil's hash functions" ON)
72-
option(IPC_TOOLKIT_WITH_CODE_COVERAGE "Enable coverage reporting" OFF)
72+
option(IPC_TOOLKIT_WITH_CODE_COVERAGE "Enable coverage reporting" OFF)
7373
mark_as_advanced(IPC_TOOLKIT_WITH_CODE_COVERAGE)
7474

75-
include(CMakeDependentOption)
76-
cmake_dependent_option(IPC_TOOLKIT_TEST_CCD_BENCHMARK "Enable CCD benchmark test" OFF "IPC_TOOLKIT_BUILD_TESTS" OFF)
77-
if(IPC_TOOLKIT_TEST_CCD_BENCHMARK)
78-
mark_as_advanced(CLEAR IPC_TOOLKIT_CCD_BENCHMARK_DIR)
79-
mark_as_advanced(CLEAR IPC_TOOLKIT_CCD_NEW_BENCHMARK_DIR)
80-
set(IPC_TOOLKIT_CCD_BENCHMARK_DIR "" CACHE PATH "Path to the CCD benchmark directory")
81-
set(IPC_TOOLKIT_CCD_NEW_BENCHMARK_DIR "" CACHE PATH "Path to the new CCD benchmark directory")
82-
else()
83-
mark_as_advanced(FORCE IPC_TOOLKIT_CCD_BENCHMARK_DIR)
84-
mark_as_advanced(FORCE IPC_TOOLKIT_CCD_NEW_BENCHMARK_DIR)
85-
endif()
86-
8775
# Set default minimum C++ standard
8876
if(IPC_TOOLKIT_TOPLEVEL_PROJECT)
8977
set(CMAKE_CXX_STANDARD 17)
@@ -110,7 +98,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
11098
# IPC Toolkit Library
11199
################################################################################
112100

113-
# Add an empty library and fill in the list of sources in `src/CMakeLists.txt`.
101+
# Add an empty library and fill in the list of sources in `src/ipc/CMakeLists.txt`.
114102
add_library(ipc_toolkit)
115103
add_library(ipc::toolkit ALIAS ipc_toolkit)
116104

src/ipc/distance/edge_edge_mollifier.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,31 @@ Matrix12d edge_edge_cross_squarednorm_hessian(
4141

4242
double edge_edge_mollifier(const double x, const double eps_x)
4343
{
44-
const double x_div_eps_x = x / eps_x;
45-
return (-x_div_eps_x + 2.0) * x_div_eps_x;
44+
if (x < eps_x) {
45+
const double x_div_eps_x = x / eps_x;
46+
return (-x_div_eps_x + 2.0) * x_div_eps_x;
47+
} else {
48+
return 1.0;
49+
}
4650
}
4751

4852
double edge_edge_mollifier_gradient(const double x, const double eps_x)
4953
{
50-
const double one_div_eps_x = 1.0 / eps_x;
51-
return 2.0 * one_div_eps_x * (-one_div_eps_x * x + 1.0);
54+
if (x < eps_x) {
55+
const double one_div_eps_x = 1.0 / eps_x;
56+
return 2.0 * one_div_eps_x * (-one_div_eps_x * x + 1.0);
57+
} else {
58+
return 0.0;
59+
}
5260
}
5361

5462
double edge_edge_mollifier_hessian(const double x, const double eps_x)
5563
{
56-
return -2.0 / (eps_x * eps_x);
64+
if (x < eps_x) {
65+
return -2.0 / (eps_x * eps_x);
66+
} else {
67+
return 0.0;
68+
}
5769
}
5870

5971
double edge_edge_mollifier(

tests/CMakeLists.txt

Lines changed: 38 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,42 @@
22
# Tests
33
################################################################################
44

5-
add_executable(ipc_toolkit_tests
6-
main.cpp
7-
8-
# Test barrier and dertivatives
9-
barrier/test_barrier.cpp
10-
11-
# Test candidates
12-
candidates/test_candidates.cpp
13-
14-
# Test CCD
15-
broad_phase/benchmark_broad_phase.cpp
16-
broad_phase/brute_force_comparison.cpp
17-
broad_phase/test_aabb.cpp
18-
broad_phase/test_broad_phase.cpp
19-
broad_phase/test_spatial_hash.cpp
20-
broad_phase/test_voxel_size_heuristic.cpp
21-
ccd/benchmark_ccd.cpp
22-
ccd/collision_generator.cpp
23-
ccd/test_ccd.cpp
24-
ccd/test_ccd_benchmark.cpp
25-
ccd/test_point_point_ccd.cpp
26-
ccd/test_point_edge_ccd.cpp
27-
ccd/test_point_triangle_ccd.cpp
28-
ccd/test_edge_edge_ccd.cpp
29-
ccd/test_ccd.cpp
30-
test_cfl.cpp
31-
32-
# Test distances and dertivatives
33-
distance/test_distance_type.cpp
34-
distance/test_edge_edge.cpp
35-
distance/test_line_line.cpp
36-
distance/test_point_edge.cpp
37-
distance/test_point_line.cpp
38-
distance/test_point_plane.cpp
39-
distance/test_point_point.cpp
40-
distance/test_point_triangle.cpp
41-
42-
# Test collision constraints
43-
collisions/test_constraints.cpp
44-
45-
# Test friction
46-
friction/friction_data_generator.cpp
47-
friction/test_closest_point.cpp
48-
friction/test_force_jacobian.cpp
49-
friction/test_friction.cpp
50-
friction/test_normal_force_magnitude.cpp
51-
friction/test_relative_velocity.cpp
52-
friction/test_smooth_friction_mollifier.cpp
53-
friction/test_tangent_basis.cpp
54-
55-
# Test general interface
56-
test_ipc.cpp
57-
test_collision_mesh.cpp
58-
59-
# Test intersection checks
60-
test_has_intersections.cpp
61-
62-
# Tes utility functions
63-
test_utils.cpp
64-
65-
# Utilities for tests
66-
utils.cpp
67-
68-
benchmark_eigen.cpp
69-
)
70-
71-
target_include_directories(ipc_toolkit_tests PUBLIC ".")
5+
include(CMakeDependentOption)
6+
cmake_dependent_option(IPC_TOOLKIT_TESTS_CCD_BENCHMARK "Enable CCD benchmark test" OFF "IPC_TOOLKIT_BUILD_TESTS" OFF)
7+
if(IPC_TOOLKIT_TESTS_CCD_BENCHMARK)
8+
mark_as_advanced(CLEAR IPC_TOOLKIT_TESTS_CCD_BENCHMARK_DIR)
9+
mark_as_advanced(CLEAR IPC_TOOLKIT_TESTS_NEW_CCD_BENCHMARK_DIR)
10+
set(IPC_TOOLKIT_TESTS_CCD_BENCHMARK_DIR "" CACHE PATH "Path to the CCD benchmark directory")
11+
set(IPC_TOOLKIT_TESTS_NEW_CCD_BENCHMARK_DIR "" CACHE PATH "Path to the new CCD benchmark directory")
12+
else()
13+
mark_as_advanced(FORCE IPC_TOOLKIT_TESTS_CCD_BENCHMARK_DIR)
14+
mark_as_advanced(FORCE IPC_TOOLKIT_TESTS_NEW_CCD_BENCHMARK_DIR)
15+
endif()
16+
17+
### Configuration
18+
set(IPC_TOOLKIT_TESTS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/tests")
19+
set(IPC_TOOLKIT_TESTS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
20+
21+
### Data directory
22+
cmake_path(APPEND IPC_TOOLKIT_TESTS_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}" "data")
23+
24+
################################################################################
25+
# IPC Toolkit Tests Executable
26+
################################################################################
27+
28+
# Add an empty library and fill in the list of sources in `src/tests/CMakeLists.txt`.
29+
add_executable(ipc_toolkit_tests)
30+
31+
# Fill in configuration options
32+
configure_file(
33+
"${IPC_TOOLKIT_TESTS_SOURCE_DIR}/config.hpp.in"
34+
"${IPC_TOOLKIT_TESTS_SOURCE_DIR}/config.hpp")
35+
36+
# Add source and header files to ipc_toolkit_tests
37+
add_subdirectory("${IPC_TOOLKIT_TESTS_SOURCE_DIR}")
38+
39+
# Public include directory for IPC Toolkit tests
40+
target_include_directories(ipc_toolkit_tests PUBLIC "${IPC_TOOLKIT_TESTS_INCLUDE_DIR}")
7241

7342
################################################################################
7443
# Required Libraries
@@ -85,17 +54,14 @@ target_link_libraries(ipc_toolkit_tests PUBLIC finitediff::finitediff)
8554
include(json)
8655
target_link_libraries(ipc_toolkit_tests PUBLIC nlohmann_json::nlohmann_json)
8756

88-
if (IPC_TOOLKIT_TEST_CCD_BENCHMARK)
57+
if (IPC_TOOLKIT_TESTS_CCD_BENCHMARK)
8958
include(ccd_query_io)
9059
target_link_libraries(ipc_toolkit_tests PUBLIC ccd_io::ccd_io)
91-
target_compile_definitions(ipc_toolkit_tests PRIVATE IPC_TOOLKIT_TEST_CCD_BENCHMARK)
9260
if(NOT (IPC_TOOLKIT_CCD_BENCHMARK_DIR STREQUAL ""))
9361
message(STATUS "Using CCD benchmark directory: ${IPC_TOOLKIT_CCD_BENCHMARK_DIR}")
94-
target_compile_definitions(ipc_toolkit_tests PRIVATE IPC_TOOLKIT_CCD_BENCHMARK_DIR="${IPC_TOOLKIT_CCD_BENCHMARK_DIR}")
9562
endif()
9663
if(NOT (IPC_TOOLKIT_CCD_NEW_BENCHMARK_DIR STREQUAL ""))
9764
message(STATUS "Using new CCD benchmark directory: ${IPC_TOOLKIT_CCD_NEW_BENCHMARK_DIR}")
98-
target_compile_definitions(ipc_toolkit_tests PRIVATE IPC_TOOLKIT_CCD_NEW_BENCHMARK_DIR="${IPC_TOOLKIT_CCD_NEW_BENCHMARK_DIR}")
9965
endif()
10066
endif()
10167

@@ -114,13 +80,6 @@ target_link_libraries(ipc_toolkit_tests PRIVATE ipc::toolkit::warnings)
11480

11581
target_compile_definitions(ipc_toolkit_tests PUBLIC CATCH_CONFIG_ENABLE_BENCHMARKING)
11682

117-
# Test data directory definition
118-
if(WIN32)
119-
target_compile_definitions(ipc_toolkit_tests PUBLIC TEST_DATA_DIR_CSTR="${CMAKE_CURRENT_SOURCE_DIR}\\\\data\\\\")
120-
else()
121-
target_compile_definitions(ipc_toolkit_tests PUBLIC TEST_DATA_DIR_CSTR="${CMAKE_CURRENT_SOURCE_DIR}/data/")
122-
endif()
123-
12483
################################################################################
12584
# Register tests
12685
################################################################################
@@ -131,4 +90,4 @@ include(Catch)
13190

13291
# Register tests
13392
set(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS ON)
134-
catch_discover_tests(ipc_toolkit_tests)
93+
catch_discover_tests(ipc_toolkit_tests)

tests/broad_phase/test_spatial_hash.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/src/tests/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
set(SOURCES
2+
main.cpp
3+
config.hpp
4+
5+
# Tests
6+
test_cfl.cpp
7+
test_collision_mesh.cpp
8+
test_has_intersections.cpp
9+
test_ipc.cpp
10+
test_utils.cpp
11+
12+
# Benchmarks
13+
benchmark_eigen.cpp
14+
15+
# Utilities
16+
utils.cpp
17+
utils.hpp
18+
)
19+
20+
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
21+
target_sources(ipc_toolkit_tests PRIVATE ${SOURCES})
22+
23+
################################################################################
24+
# Subfolders
25+
################################################################################
26+
27+
add_subdirectory(barrier)
28+
add_subdirectory(broad_phase)
29+
add_subdirectory(candidates)
30+
add_subdirectory(ccd)
31+
add_subdirectory(collisions)
32+
add_subdirectory(distance)
33+
add_subdirectory(friction)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(SOURCES
2+
# Tests
3+
test_barrier.cpp
4+
5+
# Benchmarks
6+
7+
# Utilities
8+
)
9+
10+
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
11+
target_sources(ipc_toolkit_tests PRIVATE ${SOURCES})
12+
13+
################################################################################
14+
# Subfolders
15+
################################################################################
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#include <Eigen/Core>
2-
#include <catch2/catch_all.hpp>
3-
4-
#include <finitediff.hpp>
1+
#include <catch2/catch_test_macros.hpp>
2+
#include <catch2/catch_approx.hpp>
3+
#include <catch2/generators/catch_generators_range.hpp>
4+
#include <catch2/generators/catch_generators_random.hpp>
5+
#include <catch2/generators/catch_generators_adapters.hpp>
56

67
#include <ipc/barrier/barrier.hpp>
78

9+
#include <finitediff.hpp>
10+
811
namespace {
912
double normalized_barrier(const double d, const double dhat)
1013
{
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#include <catch2/catch_all.hpp>
1+
#include <catch2/catch_test_macros.hpp>
2+
#include <catch2/benchmark/catch_benchmark.hpp>
23

34
#include <ipc/distance/point_point.hpp>
45
#include <ipc/distance/line_line.hpp>
56
#include <ipc/distance/point_triangle.hpp>
6-
#include <ipc/utils/eigen_ext.hpp>
7-
#include <ipc/utils/logger.hpp>
87

98
#include <Eigen/Geometry>
109

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set(SOURCES
2+
# Tests
3+
test_aabb.cpp
4+
test_broad_phase.cpp
5+
test_spatial_hash.cpp
6+
test_voxel_size_heuristic.cpp
7+
8+
# Benchmarks
9+
benchmark_broad_phase.cpp
10+
11+
# Utilities
12+
brute_force_comparison.cpp
13+
brute_force_comparison.hpp
14+
)
15+
16+
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
17+
target_sources(ipc_toolkit_tests PRIVATE ${SOURCES})
18+
19+
################################################################################
20+
# Subfolders
21+
################################################################################

0 commit comments

Comments
 (0)