From d03c111cbb3329018d72c7ed8bea2d7ac9a57045 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 21 Nov 2016 09:59:09 +0000 Subject: Add distance matrix reader test cases git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/distance_matrix_in_rips_module@1763 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: cae9765c56ff6e0a213a7835bab56f3618e4d942 --- src/common/include/gudhi/reader_utils.h | 2 +- src/common/test/CMakeLists.txt | 9 +++ src/common/test/test_distance_matrix_reader.cpp | 85 +++++++++++++++++++++++++ src/common/test/test_points_off_reader.cpp | 2 +- 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/common/test/test_distance_matrix_reader.cpp (limited to 'src') diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 5897030f..40d566d8 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -219,7 +219,7 @@ bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundar template< typename Filtration_value > std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from_csv_file(std::string filename, const char separator=';') { - bool dbg = true; + bool dbg = false; if (dbg) { std::cerr << "Using procedure read_lower_triangular_matrix_from_csv_file \n"; } diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt index 7ccdb752..baa24539 100644 --- a/src/common/test/CMakeLists.txt +++ b/src/common/test/CMakeLists.txt @@ -13,12 +13,21 @@ endif() add_executable ( poffreader_UT test_points_off_reader.cpp ) target_link_libraries(poffreader_UT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +add_executable ( distancematrixreader_UT test_distance_matrix_reader.cpp ) +target_link_libraries(distancematrixreader_UT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + # Do not forget to copy test files in current binary dir file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) +file(COPY "${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) +file(COPY "${CMAKE_SOURCE_DIR}/data/distance_matrix/full_square_distance_matrix.csv" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) # Unitary tests add_test(poffreader_UT ${CMAKE_CURRENT_BINARY_DIR}/poffreader_UT # XML format for Jenkins xUnit plugin --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/poffreader_UT.xml --log_level=test_suite --report_level=no) +add_test(distancematrixreader_UT ${CMAKE_CURRENT_BINARY_DIR}/distancematrixreader_UT + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/distancematrixreader_UT.xml --log_level=test_suite --report_level=no) + diff --git a/src/common/test/test_distance_matrix_reader.cpp b/src/common/test/test_distance_matrix_reader.cpp new file mode 100644 index 00000000..7eb7e846 --- /dev/null +++ b/src/common/test/test_distance_matrix_reader.cpp @@ -0,0 +1,85 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2016 INRIA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "distance_matrix_reader" +#include + +using Distance_matrix = std::vector>; + +BOOST_AUTO_TEST_CASE( lower_triangular_distance_matrix ) +{ + Distance_matrix from_lower_triangular; + // Read lower_triangular_distance_matrix.csv file where the separator is a ',' + from_lower_triangular = read_lower_triangular_matrix_from_csv_file("lower_triangular_distance_matrix.csv", + ','); + for (auto& i : from_lower_triangular) { + for (auto j : i) { + std::cout << j << " "; + } + std::cout << std::endl; + } + std::cout << "from_lower_triangular size = " << from_lower_triangular.size() << std::endl; + BOOST_CHECK(from_lower_triangular.size() == 5); + + for (int i = 0; i < from_lower_triangular.size(); i++) { + std::cout << "from_lower_triangular[" << i << "] size = " << from_lower_triangular[i].size() << std::endl; + BOOST_CHECK(from_lower_triangular[i].size() == i); + } + std::vector expected = {1}; + BOOST_CHECK(from_lower_triangular[0] == expected); + + expected = {2,3}; + BOOST_CHECK(from_lower_triangular[0] == expected); + + expected = {4,5,6}; + BOOST_CHECK(from_lower_triangular[0] == expected); + + expected = {7,8,9,10}; + BOOST_CHECK(from_lower_triangular[0] == expected); + +} + +BOOST_AUTO_TEST_CASE( full_square_distance_matrix ) +{ + Distance_matrix from_full_square; + // Read full_square_distance_matrix.csv file where the separator is the default one ';' + from_full_square = read_lower_triangular_matrix_from_csv_file("full_square_distance_matrix.csv"); + for (auto& i : from_full_square) { + for (auto j : i) { + std::cout << j << " "; + } + std::cout << std::endl; + } + std::cout << "from_full_square size = " << from_full_square.size() << std::endl; + BOOST_CHECK(from_full_square.size() == 5); + for (int i = 0; i < from_lower_triangular.size(); i++) { + std::cout << "from_lower_triangular[" << i << "] size = " << from_lower_triangular[i].size() << std::endl; + BOOST_CHECK(from_lower_triangular[i].size() == i); + } +} diff --git a/src/common/test/test_points_off_reader.cpp b/src/common/test/test_points_off_reader.cpp index b4f71182..0a78d190 100644 --- a/src/common/test/test_points_off_reader.cpp +++ b/src/common/test/test_points_off_reader.cpp @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2015 INRIA Saclay (France) + * Copyright (C) 2015 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by -- cgit v1.2.3