Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed from google test to catch #961

Merged
merged 5 commits into from Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -47,6 +47,7 @@ if(LIBIGL_BUILD_TUTORIALS)
endif()

if(LIBIGL_BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
Expand Down
8 changes: 4 additions & 4 deletions cmake/LibiglDownloadExternal.cmake
Expand Up @@ -134,10 +134,10 @@ function(igl_download_triangle)
endfunction()

## Google test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of date comment.

function(igl_download_googletest)
igl_download_project(googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-1.8.1
function(igl_download_catch2)
igl_download_project(catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 1faccd601d904a951142d8fba82914a8325b764e
)
endfunction()

Expand Down
89 changes: 62 additions & 27 deletions tests/CMakeLists.txt
@@ -1,55 +1,90 @@
cmake_minimum_required(VERSION 3.1)
project(libigl_tests)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake)
### Adding libIGL: choose the path to your local copy libIGL
if(NOT TARGET igl_common)
include(libigl)
else()
include(LibiglDownloadExternal)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake)

### Adding libIGL: choose the path to your local copy libIGL
if(NOT TARGET igl_common)
include(libigl)
else()
include(LibiglDownloadExternal)
endif()

### Download data
igl_download_test_data()
set(IGL_TEST_DATA ${LIBIGL_EXTERNAL}/../tests/data)

### Download Google unit test framework.
igl_download_googletest()
igl_download_catch2()
list(APPEND CMAKE_MODULE_PATH ${LIBIGL_EXTERNAL}/catch2/contrib)




# Add catch2
add_library(catch INTERFACE)
target_include_directories(catch SYSTEM INTERFACE ${LIBIGL_EXTERNAL}/catch2/single_include)


SET(TEST_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
INCLUDE_DIRECTORIES(${TEST_ROOT_DIR})
# Create test executable
add_executable(libigl_tests main.cpp test_common.h)
target_link_libraries(libigl_tests PUBLIC igl::core catch)
target_include_directories(libigl_tests PUBLIC ${CMAKE_CURRENT_LIST_DIR})

# Set TEST_DIR definition
ADD_DEFINITIONS(-DLIBIGL_DATA_DIR="${IGL_TEST_DATA}")

# Add googletest googlemock support
ADD_SUBDIRECTORY(
${LIBIGL_EXTERNAL}/googletest/googlemock
${CMAKE_CURRENT_BINARY_DIR}/gtest)
SET(GTEST_BOTH_LIBRARIES gtest gmock)
INCLUDE_DIRECTORIES(${gmock_SOURCE_DIR})
INCLUDE_DIRECTORIES(${gmock_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR})
INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include)
set(DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/data/")
target_compile_definitions(libigl_tests PUBLIC -DLIBIGL_DATA_DIR="${IGL_TEST_DATA}")


# Process code in each subdirectories: add in decreasing order of complexity
# (last added will run first and those should be the fastest tests)
IF(LIBIGL_WITH_MOSEK)
ADD_SUBDIRECTORY(${TEST_ROOT_DIR}/include/igl/mosek)
file(GLOB TEST_SRC_FILES ./include/igl/mosek/*.cpp)
file(GLOB TEST_INC_FILES ./include/igl/mosek/*.h ./include/igl/mosek/*.inl)
target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})

target_link_libraries(libigl_tests PUBLIC igl::mosek)
ENDIF()

IF(LIBIGL_WITH_CGAL)
ADD_SUBDIRECTORY(${TEST_ROOT_DIR}/include/igl/copyleft/boolean)
ADD_SUBDIRECTORY(${TEST_ROOT_DIR}/include/igl/copyleft/cgal)
file(GLOB TEST_SRC_FILES ./include/igl/copyleft/boolean/*.cpp ./include/igl/copyleft/cgal/*.cpp)
file(GLOB TEST_INC_FILES ./include/igl/copyleft/boolean/*.h ./include/igl/copyleft/cgal/*.h ./include/igl/copyleft/boolean/*.inl ./include/igl/copyleft/cgal/*.inl)
target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})

target_link_libraries(libigl_tests PUBLIC igl::cgal)
ENDIF()

IF(LIBIGL_WITH_TETGEN)
ADD_SUBDIRECTORY(${TEST_ROOT_DIR}/include/igl/copyleft/tetgen)
file(GLOB TEST_SRC_FILES ./include/igl/copyleft/tetgen/*.cpp)
file(GLOB TEST_INC_FILES ./include/igl/copyleft/tetgen/*.h ./include/igl/copyleft/tetgen/*.inl)
target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})

target_link_libraries(libigl_tests PUBLIC igl::tetgen)
ENDIF()

IF(LIBIGL_WITH_COMISO)
ADD_SUBDIRECTORY(${TEST_ROOT_DIR}/include/igl/copyleft/comiso)
file(GLOB TEST_SRC_FILES ./include/igl/copyleft/comiso/*.cpp)
file(GLOB TEST_INC_FILES ./include/igl/copyleft/comiso/*.h ./include/igl/copyleft/comiso/*.inl)
target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})

target_link_libraries(libigl_tests PUBLIC igl::comiso)
ENDIF()

ADD_SUBDIRECTORY(${TEST_ROOT_DIR}/include/igl)

file(GLOB TEST_SRC_FILES ./include/igl/*.cpp)
file(GLOB TEST_INC_FILES ./include/igl/*.h ./include/igl/*.inl)
target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})




# Register tests
set(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS ON)
include(Catch)
catch_discover_tests(libigl_tests)






6 changes: 0 additions & 6 deletions tests/include/igl/CMakeLists.txt

This file was deleted.

14 changes: 7 additions & 7 deletions tests/include/igl/avg_edge_length.cpp
Expand Up @@ -3,7 +3,7 @@
#include <iostream>


TEST(avg_edge_length, cube)
TEST_CASE("avg_edge_length: cube", "[igl]")
{
//The allowed error for this test
const double epsilon = 1e-15;
Expand Down Expand Up @@ -31,32 +31,32 @@ TEST(avg_edge_length, cube)
double avg;

avg = igl::avg_edge_length(V,F);
ASSERT_NEAR((12.*sqrt(side_sq) + 6.*sqrt(diag_sq))/(12.+6.), avg, epsilon);
REQUIRE (avg == Approx ((12.*sqrt(side_sq) + 6.*sqrt(diag_sq))/(12.+6.)).margin( epsilon));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the space between the macro and the parenthesis (to keep it consistent).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part was autogenerated with a script. There might be a lot of cases like that. I dont think it is worth to time investment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find tests/ -exec sed -i 's/REQUIRE (/REQUIRE(/g' {} \; (may need to escape the ().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On mac you need sed -i "" 's/...' instead.


//Check the regular tetrahedron
avg = igl::avg_edge_length(V,F_tet);
ASSERT_NEAR(sqrt(diag_sq), avg, epsilon);
REQUIRE (avg == Approx (sqrt(diag_sq)).margin( epsilon));


//Scale the cube to have huge sides
side_sq = huge_scale * huge_scale; //squared lenght of a side
diag_sq = 2.0 * side_sq; //squared lenght of a diagonal
avg = igl::avg_edge_length(V_huge,F);
ASSERT_NEAR((12.*sqrt(side_sq) + 6.*sqrt(diag_sq))/(12.+6.), avg, epsilon*huge_scale);
REQUIRE (avg == Approx ((12.*sqrt(side_sq) + 6.*sqrt(diag_sq))/(12.+6.)).margin( epsilon*huge_scale));

//Check the equilateral triangles
avg = igl::avg_edge_length(V_huge,F_tet);
ASSERT_NEAR(sqrt(diag_sq), avg, epsilon*huge_scale);
REQUIRE (avg == Approx (sqrt(diag_sq)).margin( epsilon*huge_scale));


//Scale the cube to have tiny sides
side_sq = tiny_scale * tiny_scale; //squared lenght of a side
diag_sq = 2.0 * side_sq; //squared lenght of a diagonal
avg = igl::avg_edge_length(V_tiny,F);
ASSERT_NEAR((12.*sqrt(side_sq) + 6.*sqrt(diag_sq))/(12.+6.), avg, epsilon*tiny_scale);
REQUIRE (avg == Approx ((12.*sqrt(side_sq) + 6.*sqrt(diag_sq))/(12.+6.)).margin( epsilon*tiny_scale));

//Check the regular tetrahedron
avg = igl::avg_edge_length(V_tiny,F_tet);
ASSERT_NEAR(sqrt(diag_sq), avg, epsilon*tiny_scale);
REQUIRE (avg == Approx (sqrt(diag_sq)).margin( epsilon*tiny_scale));

}
5 changes: 2 additions & 3 deletions tests/include/igl/bbw.cpp
@@ -1,12 +1,11 @@
#include <gtest/gtest.h>
#include <test_common.h>
#include <igl/boundary_conditions.h>
#include <igl/readMESH.h>
#include <igl/writeDMAT.h>
#include <igl/readTGF.h>
#include <igl/bbw.h>

TEST(bbw, decimated_knight)
TEST_CASE("bbw: decimated_knight", "[igl]")
{
Eigen::MatrixXd V,C;
Eigen::MatrixXi T,F,E;
Expand All @@ -22,6 +21,6 @@ TEST(bbw, decimated_knight)
params.active_set_params.max_iter = 100;
igl::bbw(V,T,b,bc,params,Was);
// igl::writeDMAT("decimated-knight-as.dmat",Was);
ASSERT_LT( (Was-W_groundtruth).array().abs().maxCoeff() ,1e-4);
REQUIRE (1e-4 > (Was-W_groundtruth).array().abs().maxCoeff());
}

14 changes: 7 additions & 7 deletions tests/include/igl/boundary_loop.cpp
Expand Up @@ -4,7 +4,7 @@
#include <algorithm>
#include <iostream>

TEST(boundary_loop, cube)
TEST_CASE("boundary_loop: cube", "[igl]")
{
Eigen::MatrixXd V;
Eigen::MatrixXi F;
Expand All @@ -16,10 +16,10 @@ TEST(boundary_loop, cube)
igl::boundary_loop(F, boundary);

//The cube has no boundary
ASSERT_EQ(0, boundary.size());
REQUIRE (boundary.size() == 0);
}

TEST(boundary_loop, bunny)
TEST_CASE("boundary_loop: bunny", "[igl]")
{
Eigen::MatrixXd V;
Eigen::MatrixXi F;
Expand All @@ -31,7 +31,7 @@ TEST(boundary_loop, bunny)
igl::boundary_loop(F, boundaries);

//Compare our result with known results taken from meshlab
ASSERT_EQ(5, boundaries.size());
REQUIRE (boundaries.size() == 5);

//Compute min, max and sum of boundaries
size_t boundaryMin=9999999;
Expand All @@ -45,9 +45,9 @@ TEST(boundary_loop, bunny)
}

//Total boundary has 223 vertex
ASSERT_EQ(223, boundarySum);
REQUIRE (boundarySum == 223);
//Largest loop has 80 vertex
ASSERT_EQ(80, boundaryMax);
REQUIRE (boundaryMax == 80);
//Smallest loop has 22 vertex
ASSERT_EQ(22, boundaryMin);
REQUIRE (boundaryMin == 22);
}
7 changes: 0 additions & 7 deletions tests/include/igl/copyleft/boolean/CMakeLists.txt

This file was deleted.

6 changes: 0 additions & 6 deletions tests/include/igl/copyleft/boolean/main.cpp

This file was deleted.

14 changes: 7 additions & 7 deletions tests/include/igl/copyleft/boolean/mesh_boolean.cpp
Expand Up @@ -17,16 +17,16 @@ namespace mesh_boolean_test {
Eigen::MatrixXi Eb;
igl::exterior_edges(F, Eb);

ASSERT_EQ(0, Eb.rows());
REQUIRE (Eb.rows() == 0);
}

template<typename DerivedV, typename DerivedF>
void assert_is_manifold(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F) {
Eigen::MatrixXi B;
ASSERT_TRUE(igl::is_vertex_manifold(F, B));
ASSERT_TRUE(igl::is_edge_manifold(F));
REQUIRE (igl::is_vertex_manifold(F, B));
REQUIRE (igl::is_edge_manifold(F));
}

template<typename DerivedV, typename DerivedF>
Expand All @@ -47,10 +47,10 @@ namespace mesh_boolean_test {

const int num_edges = uE.rows();
const int euler = num_vertices - num_edges + num_faces;
ASSERT_EQ(euler, 2 - 2 * genus);
REQUIRE (2 - 2 * genus == euler);
}

TEST(MeshBoolean, TwoCubes) {
TEST_CASE("MeshBoolean: TwoCubes", "[igl/copyleft/boolean]")
Eigen::MatrixXd V1;
Eigen::MatrixXi F1;
test_common::load_mesh("two-boxes-bad-self-union.ply", V1, F1);
Expand All @@ -70,7 +70,7 @@ TEST(MeshBoolean, TwoCubes) {
assert_genus_eq(Vo, Fo, 0);
}

TEST(MeshBoolean, MinusTest) {
TEST_CASE("MeshBoolean: MinusTest", "[igl/copyleft/boolean]")
// Many thanks to Eric Yao for submitting this test case.
Eigen::MatrixXd V1, V2, Vo;
Eigen::MatrixXi F1, F2, Fo;
Expand All @@ -86,7 +86,7 @@ TEST(MeshBoolean, MinusTest) {
assert_genus_eq(Vo, Fo, 1);
}

TEST(MeshBoolean, IntersectWithSelf) {
TEST_CASE("MeshBoolean: IntersectWithSelf", "[igl/copyleft/boolean]")
Eigen::MatrixXd V1, Vo;
Eigen::MatrixXi F1, Fo;
test_common::load_mesh("cube.obj", V1, F1);
Expand Down
6 changes: 0 additions & 6 deletions tests/include/igl/copyleft/cgal/CMakeLists.txt

This file was deleted.

6 changes: 3 additions & 3 deletions tests/include/igl/copyleft/cgal/CSGTree.cpp
Expand Up @@ -2,7 +2,7 @@

#include <igl/copyleft/cgal/CSGTree.h>

TEST(CSGTree, extrusion) {
TEST_CASE("CSGTree: extrusion", "[igl/copyleft/cgal]")
Eigen::MatrixXd V;
Eigen::MatrixXi F;
test_common::load_mesh("extrusion.obj", V, F);
Expand All @@ -12,6 +12,6 @@ TEST(CSGTree, extrusion) {
Eigen::MatrixXd V2 = inter.cast_V<Eigen::MatrixXd>();
Eigen::MatrixXi F2 = inter.F();

ASSERT_EQ(V.rows(), V2.rows());
ASSERT_EQ(F.rows(), F2.rows());
REQUIRE (V2.rows() == V.rows());
REQUIRE (F2.rows() == F.rows());
}
4 changes: 2 additions & 2 deletions tests/include/igl/copyleft/cgal/hausdorff.cpp
Expand Up @@ -5,7 +5,7 @@
#include <igl/copyleft/cgal/point_mesh_squared_distance.h>
#include <igl/upsample.h>

TEST(hausdorff, knightVScheburashka)
TEST_CASE("hausdorff: knightVScheburashka", "[igl/copyleft/cgal]")
{
Eigen::MatrixXd VA,VB;
Eigen::MatrixXi FA,FB;
Expand Down Expand Up @@ -46,7 +46,7 @@ TEST(hausdorff, knightVScheburashka)
{
u4 = std::min(u4,U[j](i-u));
}
ASSERT_LE(u4,U[j-1](i/4));
REQUIRE (U[j-1](i/4) >= u4);
}
}
break;
Expand Down
6 changes: 0 additions & 6 deletions tests/include/igl/copyleft/cgal/main.cpp

This file was deleted.