diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2019-01-17 16:15:59 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2019-01-17 16:15:59 +0000 |
commit | 6b70186caa620f9cd734903db978b2117509f8b1 (patch) | |
tree | cb2cd36bfbeb480a6e7d7580c48591aa4d9c5440 /src/Simplex_tree/test | |
parent | a3b3e527f75ea05a7840ecf73f613f56c3c52273 (diff) | |
parent | e105da964b96218459c8822816de36273f6cdf17 (diff) |
Merge last trunk modifications
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/cubical_complex_small_fix@4062 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 495752e4da032e54a1a88adbcd030f526bc80a43
Diffstat (limited to 'src/Simplex_tree/test')
-rw-r--r-- | src/Simplex_tree/test/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp | 137 |
2 files changed, 145 insertions, 0 deletions
diff --git a/src/Simplex_tree/test/CMakeLists.txt b/src/Simplex_tree/test/CMakeLists.txt index c63d8532..5bea3938 100644 --- a/src/Simplex_tree/test/CMakeLists.txt +++ b/src/Simplex_tree/test/CMakeLists.txt @@ -28,3 +28,11 @@ if (TBB_FOUND) endif() gudhi_add_coverage_test(Simplex_tree_iostream_operator_test_unit) + +add_executable ( Simplex_tree_ctor_and_move_test_unit simplex_tree_ctor_and_move_unit_test.cpp ) +target_link_libraries(Simplex_tree_ctor_and_move_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +if (TBB_FOUND) + target_link_libraries(Simplex_tree_ctor_and_move_test_unit ${TBB_LIBRARIES}) +endif() + +gudhi_add_coverage_test(Simplex_tree_ctor_and_move_test_unit) diff --git a/src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp new file mode 100644 index 00000000..e729cf00 --- /dev/null +++ b/src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp @@ -0,0 +1,137 @@ +#include <iostream> +#include <vector> +#include <string> + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "simplex_tree_constructor_and_move" +#include <boost/test/unit_test.hpp> +#include <boost/mpl/list.hpp> + +// ^ +// /!\ Nothing else from Simplex_tree shall be included to test includes are well defined. +#include "gudhi/Simplex_tree.h" + +using namespace Gudhi; + +typedef boost::mpl::list<Simplex_tree<>, Simplex_tree<Simplex_tree_options_fast_persistence>> list_of_tested_variants; + +template<typename Simplex_tree> +void print_simplex_filtration(Simplex_tree& st, const std::string& msg) { + // Required before browsing through filtration values + st.initialize_filtration(); + + std::cout << "********************************************************************\n"; + std::cout << "* " << msg << "\n"; + std::cout << "* The complex contains " << st.num_simplices() << " simplices"; + std::cout << " - dimension " << st.dimension() << "\n"; + std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; + for (auto f_simplex : st.filtration_simplex_range()) { + std::cout << " " + << "[" << st.filtration(f_simplex) << "] "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) std::cout << "(" << vertex << ")"; + std::cout << std::endl; + } + +} + +BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_copy_constructor, Simplex_tree, list_of_tested_variants) { + Simplex_tree st; + + st.insert_simplex_and_subfaces({2, 1, 0}, 3.0); + st.insert_simplex_and_subfaces({0, 1, 6, 7}, 4.0); + st.insert_simplex_and_subfaces({3, 0}, 2.0); + st.insert_simplex_and_subfaces({3, 4, 5}, 3.0); + st.insert_simplex_and_subfaces({8}, 1.0); + /* Inserted simplex: */ + /* 1 6 */ + /* o---o */ + /* /X\7/ */ + /* o---o---o---o o */ + /* 2 0 3\X/4 8 */ + /* o */ + /* 5 */ + /* */ + /* In other words: */ + /* A facet [2,1,0] */ + /* An edge [0,3] */ + /* A facet [3,4,5] */ + /* A cell [0,1,6,7] */ + /* A vertex [8] */ + + print_simplex_filtration(st, "Default Simplex_tree is initialized"); + + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF COPY CONSTRUCTOR" << std::endl; + + Simplex_tree st1(st); + Simplex_tree st2(st); + print_simplex_filtration(st1, "First copy constructor from the default Simplex_tree"); + print_simplex_filtration(st2, "Second copy constructor from the default Simplex_tree"); + // Cross check + BOOST_CHECK(st1 == st2); + BOOST_CHECK(st == st2); + BOOST_CHECK(st1 == st); + + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF COPY ASSIGNMENT" << std::endl; + Simplex_tree st3; + // To check there is no memory leak + st3.insert_simplex_and_subfaces({9, 10, 11}, 200.0); + st3 = st; + print_simplex_filtration(st3, "First copy assignment from the default Simplex_tree"); + Simplex_tree st4; + st4 = st; + print_simplex_filtration(st4, "Second copy assignment from the default Simplex_tree"); + + // Cross check + BOOST_CHECK(st3 == st4); + BOOST_CHECK(st == st4); + BOOST_CHECK(st3 == st); + + st = st; + print_simplex_filtration(st4, "Third self copy assignment from the default Simplex_tree"); + + BOOST_CHECK(st3 == st); + + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF MOVE CONSTRUCTOR" << std::endl; + Simplex_tree st5(std::move(st1)); + print_simplex_filtration(st5, "First move constructor from the default Simplex_tree"); + print_simplex_filtration(st1, "First moved Simplex_tree shall be empty"); + Simplex_tree st6(std::move(st2)); + print_simplex_filtration(st6, "Second move constructor from the default Simplex_tree"); + print_simplex_filtration(st2, "Second moved Simplex_tree shall be empty"); + + // Cross check + BOOST_CHECK(st5 == st6); + BOOST_CHECK(st == st6); + BOOST_CHECK(st5 == st); + + Simplex_tree empty_st; + BOOST_CHECK(st1 == st2); + BOOST_CHECK(empty_st == st2); + BOOST_CHECK(st1 == empty_st); + + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF MOVE ASSIGNMENT" << std::endl; + + Simplex_tree st7; + // To check there is no memory leak + st7.insert_simplex_and_subfaces({9, 10, 11}, 200.0); + st7 = std::move(st3); + print_simplex_filtration(st7, "First move assignment from the default Simplex_tree"); + Simplex_tree st8; + st8 = std::move(st4); + print_simplex_filtration(st8, "Second move assignment from the default Simplex_tree"); + + // Cross check + BOOST_CHECK(st7 == st8); + BOOST_CHECK(st == st8); + BOOST_CHECK(st7 == st); + + st = std::move(st); + print_simplex_filtration(st, "Third self move assignment from the default Simplex_tree"); + + BOOST_CHECK(st7 == st); + +} |