summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology
diff options
context:
space:
mode:
Diffstat (limited to 'src/Persistent_cohomology')
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h8
-rw-r--r--src/Persistent_cohomology/test/CMakeLists.txt13
-rw-r--r--src/Persistent_cohomology/test/betti_numbers_unit_test.cpp9
3 files changed, 20 insertions, 10 deletions
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index 944b6d35..0f1876d0 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -600,8 +600,10 @@ class Persistent_cohomology {
* @return A vector of Betti numbers.
*/
std::vector<int> betti_numbers() const {
+ // Don't allocate a vector of negative size for an empty complex
+ int siz = std::max(dim_max_, 0);
// Init Betti numbers vector with zeros until Simplicial complex dimension
- std::vector<int> betti_numbers(dim_max_, 0);
+ std::vector<int> betti_numbers(siz);
for (auto pair : persistent_pairs_) {
// Count never ended persistence intervals
@@ -639,8 +641,10 @@ class Persistent_cohomology {
* @return A vector of persistent Betti numbers.
*/
std::vector<int> persistent_betti_numbers(Filtration_value from, Filtration_value to) const {
+ // Don't allocate a vector of negative size for an empty complex
+ int siz = std::max(dim_max_, 0);
// Init Betti numbers vector with zeros until Simplicial complex dimension
- std::vector<int> betti_numbers(dim_max_, 0);
+ std::vector<int> betti_numbers(siz);
for (auto pair : persistent_pairs_) {
// Count persistence intervals that covers the given interval
// null_simplex test : if the function is called with to=+infinity, we still get something useful. And it will
diff --git a/src/Persistent_cohomology/test/CMakeLists.txt b/src/Persistent_cohomology/test/CMakeLists.txt
index f8baf861..64669c4e 100644
--- a/src/Persistent_cohomology/test/CMakeLists.txt
+++ b/src/Persistent_cohomology/test/CMakeLists.txt
@@ -1,11 +1,9 @@
project(Persistent_cohomology_tests)
-include(GUDHI_test_coverage)
+include(GUDHI_boost_test)
add_executable ( Persistent_cohomology_test_unit persistent_cohomology_unit_test.cpp )
-target_link_libraries(Persistent_cohomology_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_executable ( Persistent_cohomology_test_betti_numbers betti_numbers_unit_test.cpp )
-target_link_libraries(Persistent_cohomology_test_betti_numbers ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
if (TBB_FOUND)
target_link_libraries(Persistent_cohomology_test_unit ${TBB_LIBRARIES})
target_link_libraries(Persistent_cohomology_test_betti_numbers ${TBB_LIBRARIES})
@@ -16,13 +14,12 @@ file(COPY "${CMAKE_SOURCE_DIR}/src/Persistent_cohomology/test/simplex_tree_file_
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
# Unitary tests
-gudhi_add_coverage_test(Persistent_cohomology_test_unit)
-gudhi_add_coverage_test(Persistent_cohomology_test_betti_numbers)
+gudhi_add_boost_test(Persistent_cohomology_test_unit)
+gudhi_add_boost_test(Persistent_cohomology_test_betti_numbers)
if(GMPXX_FOUND AND GMP_FOUND)
add_executable ( Persistent_cohomology_test_unit_multi_field persistent_cohomology_unit_test_multi_field.cpp )
- target_link_libraries(Persistent_cohomology_test_unit_multi_field
- ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
+ target_link_libraries(Persistent_cohomology_test_unit_multi_field ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
if (TBB_FOUND)
target_link_libraries(Persistent_cohomology_test_unit_multi_field ${TBB_LIBRARIES})
endif(TBB_FOUND)
@@ -31,7 +28,7 @@ if(GMPXX_FOUND AND GMP_FOUND)
file(COPY "${CMAKE_SOURCE_DIR}/src/Persistent_cohomology/test/simplex_tree_file_for_multi_field_unit_test.txt"
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
# Unitary tests
- gudhi_add_coverage_test(Persistent_cohomology_test_unit_multi_field)
+ gudhi_add_boost_test(Persistent_cohomology_test_unit_multi_field)
endif(GMPXX_FOUND AND GMP_FOUND)
diff --git a/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp b/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp
index 0a08d200..b9f11607 100644
--- a/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp
+++ b/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp
@@ -284,4 +284,13 @@ BOOST_AUTO_TEST_CASE( betti_numbers )
auto intervals_in_dimension_2 = pcoh.intervals_in_dimension(2);
std::cout << "intervals_in_dimension_2.size() = " << intervals_in_dimension_2.size() << std::endl;
BOOST_CHECK(intervals_in_dimension_2.size() == 0);
+
+ std::cout << "EMPTY COMPLEX" << std::endl;
+ Simplex_tree empty;
+ empty.initialize_filtration();
+ St_persistence pcoh_empty(empty, false);
+ pcoh_empty.init_coefficients(2);
+ pcoh_empty.compute_persistent_cohomology();
+ BOOST_CHECK(pcoh_empty.betti_numbers().size() == 0);
+ BOOST_CHECK(pcoh_empty.persistent_betti_numbers(0,1).size() == 0);
}