From 429d4f06cede4d97144592eff91689fc1c707474 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 10 Dec 2014 14:04:18 +0000 Subject: Add persistent unit test - warning fix - cpplint fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/cpplint_test@346 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9ef774de762c68a449b2a9791085f58c39a0705e --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 63 ++-- .../gudhi/Simplex_tree/Simplex_tree_iterators.h | 15 +- .../Simplex_tree_node_explicit_storage.h | 25 +- .../include/gudhi/Simplex_tree/indexing_tag.h | 7 +- src/Simplex_tree/test/CMakeLists.txt | 18 +- src/Simplex_tree/test/README | 2 +- src/Simplex_tree/test/UnitTestSimplexTree.cpp | 400 --------------------- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 400 +++++++++++++++++++++ 8 files changed, 458 insertions(+), 472 deletions(-) delete mode 100644 src/Simplex_tree/test/UnitTestSimplexTree.cpp create mode 100644 src/Simplex_tree/test/simplex_tree_unit_test.cpp (limited to 'src/Simplex_tree') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 6430c300..9b3de20a 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -20,20 +20,22 @@ * along with this program. If not, see . */ -#ifndef GUDHI_SIMPLEX_TREE_H -#define GUDHI_SIMPLEX_TREE_H +#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_H_ +#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_H_ + +#include +#include +#include +#include -#include -#include -#include -#include "gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h" -#include "gudhi/Simplex_tree/Simplex_tree_siblings.h" -#include "gudhi/Simplex_tree/Simplex_tree_iterators.h" -#include "gudhi/Simplex_tree/indexing_tag.h" #include #include #include +#include +#include +#include + namespace Gudhi { /** \defgroup simplex_tree Filtered Complexes Package @@ -107,18 +109,12 @@ class Simplex_tree { /* Type of dictionary Vertex_handle -> Node for traversing the simplex tree. */ typedef typename boost::container::flat_map Dictionary; - friend class Simplex_tree_node_explicit_storage< - Simplex_tree > ; - friend class Simplex_tree_siblings< - Simplex_tree, Dictionary> ; - friend class Simplex_tree_simplex_vertex_iterator< - Simplex_tree > ; - friend class Simplex_tree_boundary_simplex_iterator< - Simplex_tree > ; - friend class Simplex_tree_complex_simplex_iterator< - Simplex_tree > ; - friend class Simplex_tree_skeleton_simplex_iterator< - Simplex_tree > ; + friend class Simplex_tree_node_explicit_storage< Simplex_tree >; + friend class Simplex_tree_siblings< Simplex_tree, Dictionary>; + friend class Simplex_tree_simplex_vertex_iterator< Simplex_tree >; + friend class Simplex_tree_boundary_simplex_iterator< Simplex_tree >; + friend class Simplex_tree_complex_simplex_iterator< Simplex_tree >; + friend class Simplex_tree_skeleton_simplex_iterator< Simplex_tree >; template friend class Persistent_cohomology; /* \brief Set of nodes sharing a same parent in the simplex tree. */ @@ -400,7 +396,7 @@ class Simplex_tree { * Vertex_handle. */ template - Simplex_handle find(RandomAccessVertexRange & s) { + Simplex_handle find(const RandomAccessVertexRange & s) { if (s.begin() == s.end()) std::cerr << "Empty simplex \n"; @@ -597,7 +593,7 @@ class Simplex_tree { * Reverse lexicographic order has the property to always consider the subsimplex of a simplex * to be smaller. The filtration function must be monotonic. */ struct is_before_in_filtration { - is_before_in_filtration(Simplex_tree * st) + explicit is_before_in_filtration(Simplex_tree * st) : st_(st) { } @@ -632,7 +628,7 @@ class Simplex_tree { * boost::graph_traits::directed_category * must be undirected_tag. */ template - void insert_graph(OneSkeletonGraph & skel_graph) { + void insert_graph(const OneSkeletonGraph& skel_graph) { assert(num_simplices() == 0); // the simplex tree must be empty if (boost::num_vertices(skel_graph) == 0) { @@ -738,25 +734,22 @@ class Simplex_tree { } /** \brief Intersects Dictionary 1 [begin1;end1) with Dictionary 2 [begin2,end2) * and assigns the maximal possible Filtration_value to the Nodes. */ - void intersection(std::vector > & intersection, + void intersection(std::vector >& intersection, Dictionary_it begin1, Dictionary_it end1, Dictionary_it begin2, Dictionary_it end2, Filtration_value filtration) { if (begin1 == end1 || begin2 == end2) - return; // 0; + return; // ----->> while (true) { if (begin1->first == begin2->first) { intersection.push_back( std::pair( begin1->first, - Node( - NULL, - maximum(begin1->second.filtration(), - begin2->second.filtration(), filtration)))); + Node(NULL, maximum(begin1->second.filtration(), begin2->second.filtration(), filtration)))); ++begin1; ++begin2; if (begin1 == end1 || begin2 == end2) - return; + return; // ----->> } else { if (begin1->first < begin2->first) { ++begin1; @@ -765,7 +758,7 @@ class Simplex_tree { } else { ++begin2; if (begin2 == end2) - return; + return; // ----->> } } } @@ -784,7 +777,7 @@ class Simplex_tree { * dim idx_1 ... idx_k fil where dim is the dimension of the simplex, * idx_1 ... idx_k are the row index (starting from 0) of the simplices of the boundary * of the simplex, and fil is its filtration value. */ - void print_hasse(std::ostream & os) { + void print_hasse(std::ostream& os) { os << num_simplices() << " " << std::endl; for (auto sh : filtration_simplex_range(Indexing_tag())) { os << dimension(sh) << " "; @@ -832,7 +825,7 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { size_t num_simplices = 0; while (read_simplex(is, simplex, fil)) { // read all simplices in the file as a list of vertices ++num_simplices; - int dim = (int) simplex.size() - 1; // Warning : simplex_size needs to be casted in int - Can be 0 + int dim = static_cast(simplex.size() - 1); // Warning : simplex_size needs to be casted in int - Can be 0 if (max_dim < dim) { max_dim = dim; } @@ -852,4 +845,4 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { /** @} */ // end defgroup simplex_tree } // namespace Gudhi -#endif // GUDHI_SIMPLEX_TREE_H +#endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index 54d4d296..06462c88 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -20,12 +20,13 @@ * along with this program. If not, see . */ -#ifndef SIMPLEX_TREE_ITERATORS_H -#define SIMPLEX_TREE_ITERATORS_H +#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ +#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ -#include #include +#include + namespace Gudhi { /* \addtogroup simplex_tree @@ -47,7 +48,7 @@ class Simplex_tree_simplex_vertex_iterator : public boost::iterator_facade< typedef typename SimplexTree::Siblings Siblings; typedef typename SimplexTree::Vertex_handle Vertex_handle; - Simplex_tree_simplex_vertex_iterator(SimplexTree * st) + explicit Simplex_tree_simplex_vertex_iterator(SimplexTree * st) : // any end() iterator sib_(NULL), v_(st->null_vertex()) { @@ -93,7 +94,7 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< typedef typename SimplexTree::Siblings Siblings; // any end() iterator - Simplex_tree_boundary_simplex_iterator(SimplexTree * st) + explicit Simplex_tree_boundary_simplex_iterator(SimplexTree * st) : last_(st->null_vertex()), sib_(NULL) { } @@ -166,7 +167,7 @@ class Simplex_tree_complex_simplex_iterator : public boost::iterator_facade< : st_(NULL) { } - Simplex_tree_complex_simplex_iterator(SimplexTree * st) + explicit Simplex_tree_complex_simplex_iterator(SimplexTree * st) : st_(st) { if (st == NULL || st->root() == NULL || st->root()->members().empty()) { st_ = NULL; @@ -302,4 +303,4 @@ class Simplex_tree_skeleton_simplex_iterator : public boost::iterator_facade< /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SIMPLEX_TREE_ITERATORS_H +#endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h index 27120f00..1f1a34cc 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h @@ -20,11 +20,10 @@ * along with this program. If not, see . */ -#ifndef GUDHI_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H -#define GUDHI_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H +#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ +#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ #include -#include namespace Gudhi { @@ -42,14 +41,10 @@ namespace Gudhi { template class Simplex_tree_node_explicit_storage { public: -// friend SimplexTree; - typedef typename SimplexTree::Siblings Siblings; typedef typename SimplexTree::Filtration_value Filtration_value; typedef typename SimplexTree::Simplex_key Simplex_key; - //private: - //friend class Simplex_tree; // Default constructor. Simplex_tree_node_explicit_storage() : children_(NULL), @@ -68,13 +63,6 @@ class Simplex_tree_node_explicit_storage { simplex_key_ = key; } - /* - * Return true if the node has children, - * false otherwise. - */ - //bool has_children(Vertex label) - //{ //if(children_ == NULL) return false; //for root simplices - // return (children_->parent() == label);} /* * Assign a children to the node */ @@ -92,7 +80,7 @@ class Simplex_tree_node_explicit_storage { return filtration_; } - /* Careful -> has_children() must be true*/ + /* Careful -> children_ can be NULL*/ Siblings * children() { return children_; } @@ -106,11 +94,10 @@ class Simplex_tree_node_explicit_storage { // Data attached to simplex, explicit storage Simplex_key simplex_key_; - Filtration_value filtration_; //value in the filtration - + Filtration_value filtration_; // value in the filtration }; /* @} */ // end addtogroup simplex_tree -}// namespace Gudhi +} // namespace Gudhi -#endif // GUDHI_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H +#endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h b/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h index 680458a5..69ffa44b 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h @@ -20,6 +20,9 @@ * along with this program. If not, see . */ +#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_INDEXING_TAG_H_ +#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_INDEXING_TAG_H_ + namespace Gudhi { /** \brief Tag for a linear ordering of simplices. @@ -31,4 +34,6 @@ struct linear_indexing_tag { /* \brief Tag for a zigzag ordering of simplices. */ // struct zigzag_indexing_tag {}; -}// namespace Gudhi +} // namespace Gudhi + +#endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_INDEXING_TAG_H_ diff --git a/src/Simplex_tree/test/CMakeLists.txt b/src/Simplex_tree/test/CMakeLists.txt index eeb066d4..d7f968af 100644 --- a/src/Simplex_tree/test/CMakeLists.txt +++ b/src/Simplex_tree/test/CMakeLists.txt @@ -12,22 +12,22 @@ if(NOT MSVC) endif() include_directories(${Boost_INCLUDE_DIRS}) -add_executable ( TestSimplexTree UnitTestSimplexTree.cpp ) -target_link_libraries(TestSimplexTree ${Boost_LIBRARIES}) +add_executable ( simplex_tree_unit_test simplex_tree_unit_test.cpp ) +target_link_libraries(simplex_tree_unit_test ${Boost_LIBRARIES}) # Unitary tests -add_test(TestSimplexTree ${CMAKE_CURRENT_BINARY_DIR}/TestSimplexTree) +add_test(simplex_tree_unit_test ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_unit_test) if (LCOV_PATH) # Lcov code coverage of unitary test - add_test(TestSimplexTreeCov ${CMAKE_SOURCE_DIR}/scripts/check_code_coverage.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree) + add_test(simplex_tree_unit_test_coverage.info ${CMAKE_SOURCE_DIR}/scripts/check_code_coverage.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree) endif() if (PYTHON_PATH) # Cpplint tests on coding style - add_test(CpplintSimplexTree ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree.h) - add_test(CpplintSimplexTreeIndexingTag ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h) - add_test(CpplintSimplexTreeIterator ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h) - add_test(CpplintSimplexTreeNode ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h) - add_test(CpplintSimplexTreeSiblings ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h) + add_test(Simplex_tree.h.cpplint ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree.h) + add_test(indexing_tag.h.cpplint ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h) + add_test(Simplex_tree_iterators.h.cpplint ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h) + add_test(Simplex_tree_node_explicit_storage.h.cpplint ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h) + add_test(Simplex_tree_siblings.h.cpplint ${CMAKE_SOURCE_DIR}/scripts/check_google_style.sh ${CMAKE_SOURCE_DIR}/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h) endif() \ No newline at end of file diff --git a/src/Simplex_tree/test/README b/src/Simplex_tree/test/README index 3d6981ff..620bcd5f 100644 --- a/src/Simplex_tree/test/README +++ b/src/Simplex_tree/test/README @@ -7,6 +7,6 @@ make To launch with details: *********************** -./TestSimplexTree --report_level=detailed --log_level=all +./simplex_tree_unit_test --report_level=detailed --log_level=all ==> echo $? returns 0 in case of success (non-zero otherwise) diff --git a/src/Simplex_tree/test/UnitTestSimplexTree.cpp b/src/Simplex_tree/test/UnitTestSimplexTree.cpp deleted file mode 100644 index a3671f56..00000000 --- a/src/Simplex_tree/test/UnitTestSimplexTree.cpp +++ /dev/null @@ -1,400 +0,0 @@ -#define BOOST_TEST_MODULE const_string test -#include -#include -#include -#include -#include - -#include // std::pair, std::make_pair - -#include // float comparison -#include - -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/reader_utils.h" -#include "gudhi/Simplex_tree.h" - - -using namespace Gudhi; - -typedef Simplex_tree<> typeST; -typedef std::pair< typeST::Simplex_handle, bool > typePairSimplexBool; -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef std::pair typeSimplex; - -const Vertex_handle DEFAULT_VERTEX_HANDLE = (const Vertex_handle)-1; - -void test_empty_simplex_tree(typeST& tst) -{ - BOOST_CHECK( tst.null_vertex() == DEFAULT_VERTEX_HANDLE ); - BOOST_CHECK( tst.filtration() == Filtration_value(0) ); - BOOST_CHECK( tst.num_vertices() == (size_t)0 ); - BOOST_CHECK( tst.num_simplices() == (size_t)0 ); - typeST::Siblings* STRoot = tst.root(); - BOOST_CHECK( STRoot != NULL ); - BOOST_CHECK( STRoot->oncles() == NULL ); - BOOST_CHECK( STRoot->parent() == DEFAULT_VERTEX_HANDLE ); - BOOST_CHECK( tst.dimension() == -1 ); -} - -void test_iterators_on_empty_simplex_tree(typeST& tst) -{ - std::cout << "Iterator on vertices: " << std::endl; - for( auto vertex : tst.complex_vertex_range() ) - { - std::cout << "vertice:" << vertex << std::endl; - BOOST_CHECK( false); // shall be empty - } - std::cout << "Iterator on simplices: " << std::endl; - for( auto simplex : tst.complex_simplex_range() ) - { - BOOST_CHECK( false); // shall be empty - } - - std::cout << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - for( auto f_simplex : tst.filtration_simplex_range() ) - { - BOOST_CHECK( false); // shall be empty - std::cout << "test_simplex_tree_contains - filtration=" << tst.filtration(f_simplex) << std::endl; - } -} - -BOOST_AUTO_TEST_CASE( simplex_tree_when_empty ) -{ - const Filtration_value DEFAULT_FILTRATION_VALUE = 0; - - // TEST OF DEFAULT CONSTRUCTOR - std::cout << "********************************************************************" << std::endl; - std::cout << "TEST OF DEFAULT CONSTRUCTOR" << std::endl; - typeST st; - - test_empty_simplex_tree(st); - - test_iterators_on_empty_simplex_tree(st); - // TEST OF EMPTY INSERTION - std::cout << "TEST OF EMPTY INSERTION" << std::endl; - typeVectorVertex simplexVectorEmpty; - BOOST_CHECK(simplexVectorEmpty.empty() == true); - typePairSimplexBool returnEmptyValue = st.insert ( simplexVectorEmpty, DEFAULT_FILTRATION_VALUE ); - BOOST_CHECK(returnEmptyValue.first == typeST::Simplex_handle(NULL)); - BOOST_CHECK(returnEmptyValue.second == true); - - test_empty_simplex_tree(st); - - test_iterators_on_empty_simplex_tree(st); -} - -bool AreAlmostTheSame(float a, float b) -{ - return std::fabs(a - b) < std::numeric_limits::epsilon(); -} - -BOOST_AUTO_TEST_CASE( simplex_tree_from_file ) -{ - // TEST OF INSERTION - std::cout << "********************************************************************" << std::endl; - std::cout << "TEST OF SIMPLEX TREE FROM A FILE" << std::endl; - typeST st; - - std::string inputFile("simplex_tree_for_unit_test.txt"); - std::ifstream simplex_tree_stream(inputFile.c_str()); - simplex_tree_stream >> st; - - // Display the Simplex_tree - std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; - std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; - - // Check - BOOST_CHECK(st.num_simplices() == 143353); - BOOST_CHECK(st.dimension() == 3); - BOOST_CHECK(st.filtration() == 0.4); - - int previous_size=0; - for( auto f_simplex : st.filtration_simplex_range() ) - { - // Size of simplex - int size=0; - for( auto vertex : st.simplex_vertex_range(f_simplex) ) - { - size++; - } - BOOST_CHECK(AreAlmostTheSame(st.filtration(f_simplex),(0.1* size))); // Specific test: filtration = 0.1 * simplex_size - BOOST_CHECK(previous_size <= size); // Check list is sorted (because of sorted filtrations in simplex_tree.txt) - previous_size = size; - } - simplex_tree_stream.close(); -} - -void test_simplex_tree_contains(typeST& simplexTree, typeSimplex simplex, int pos) -{ - auto f_simplex = simplexTree.filtration_simplex_range().begin(); - f_simplex += pos; - std::cout << "test_simplex_tree_contains - filtration=" << simplexTree.filtration(*f_simplex) << "||" << simplex.second << std::endl; - BOOST_CHECK( AreAlmostTheSame(simplexTree.filtration(*f_simplex),simplex.second) ); - - typeVectorVertex::iterator simplexIter = simplex.first.end()-1; - for( auto vertex : simplexTree.simplex_vertex_range(*f_simplex) ) - { - std::cout << "test_simplex_tree_contains - vertex=" << vertex << "||" << *simplexIter << std::endl; - BOOST_CHECK( vertex == *simplexIter); - simplexIter--; - } -} - -void test_simplex_tree_insert_returns_true(const typePairSimplexBool& returnValue) -{ - BOOST_CHECK(returnValue.second == true); - typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned != typeST::Simplex_handle(NULL)); -} - -// Global variables -Filtration_value max_fil = 0.0; -int dim_max = -1; - -void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, const Filtration_value& fil) -{ - if (vectorSize > dim_max+1) - { - dim_max = vectorSize-1; - simplexTree.set_dimension(dim_max); - std::cout << " set_and_test_simplex_tree_dim_fil - dim_max=" << dim_max << std::endl; - } - if (fil > max_fil) - { - max_fil = fil; - simplexTree.set_filtration(max_fil); - std::cout << " set_and_test_simplex_tree_dim_fil - max_fil=" << max_fil << std::endl; - } - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); - - BOOST_CHECK( simplexTree.dimension() == dim_max ); - BOOST_CHECK( AreAlmostTheSame(simplexTree.filtration(), max_fil) ); - BOOST_CHECK( simplexTree.num_simplices() == nb_simplices ); -} - -BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) -{ - const Filtration_value FIRST_FILTRATION_VALUE = 0.1; - const Filtration_value SECOND_FILTRATION_VALUE = 0.2; - const Filtration_value THIRD_FILTRATION_VALUE = 0.3; - const Filtration_value FOURTH_FILTRATION_VALUE = 0.4; - Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle)0; - Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle)1; - Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle)2; - Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle)3; - - // TEST OF INSERTION - std::cout << "********************************************************************" << std::endl; - std::cout << "TEST OF INSERTION" << std::endl; - typeST st; - - // ++ FIRST - std::cout << " - INSERT 0" << std::endl; - typeVectorVertex firstSimplexVector; - firstSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( firstSimplexVector.size() == 1 ); - typeSimplex firstSimplex = std::make_pair(firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - typePairSimplexBool returnValue = - st.insert ( firstSimplex.first, firstSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, firstSimplexVector.size(), firstSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)1 ); - - // ++ SECOND - std::cout << " - INSERT 1" << std::endl; - typeVectorVertex secondSimplexVector; - secondSimplexVector.push_back(SECOND_VERTEX_HANDLE); - BOOST_CHECK( secondSimplexVector.size() == 1 ); - typeSimplex secondSimplex = std::make_pair(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert ( secondSimplex.first, secondSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, secondSimplexVector.size(), secondSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)2 ); - - // ++ THIRD - std::cout << " - INSERT (0,1)" << std::endl; - typeVectorVertex thirdSimplexVector; - thirdSimplexVector.push_back(FIRST_VERTEX_HANDLE); - thirdSimplexVector.push_back(SECOND_VERTEX_HANDLE); - BOOST_CHECK( thirdSimplexVector.size() == 2 ); - typeSimplex thirdSimplex = std::make_pair(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert ( thirdSimplex.first, thirdSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, thirdSimplexVector.size(), thirdSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)2 ); // Not incremented !! - - // ++ FOURTH - std::cout << " - INSERT 2" << std::endl; - typeVectorVertex fourthSimplexVector; - fourthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - BOOST_CHECK( fourthSimplexVector.size() == 1 ); - typeSimplex fourthSimplex = std::make_pair(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert ( fourthSimplex.first, fourthSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, fourthSimplexVector.size(), fourthSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)3 ); - - // ++ FIFTH - std::cout << " - INSERT (2,0)" << std::endl; - typeVectorVertex fifthSimplexVector; - fifthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - fifthSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( fifthSimplexVector.size() == 2 ); - typeSimplex fifthSimplex = std::make_pair(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert ( fifthSimplex.first, fifthSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, fifthSimplexVector.size(), fifthSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)3 ); // Not incremented !! - - // ++ SIXTH - std::cout << " - INSERT (2,1)" << std::endl; - typeVectorVertex sixthSimplexVector; - sixthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - sixthSimplexVector.push_back(SECOND_VERTEX_HANDLE); - BOOST_CHECK( sixthSimplexVector.size() == 2 ); - typeSimplex sixthSimplex = std::make_pair(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert ( sixthSimplex.first, sixthSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, sixthSimplexVector.size(), sixthSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)3 ); // Not incremented !! - - // ++ SEVENTH - std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex seventhSimplexVector; - seventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); - seventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); - seventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( seventhSimplexVector.size() == 3 ); - typeSimplex seventhSimplex = std::make_pair(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); - returnValue = - st.insert ( seventhSimplex.first, seventhSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, seventhSimplexVector.size(), seventhSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)3 ); // Not incremented !! - - // ++ EIGHTH - std::cout << " - INSERT 3" << std::endl; - typeVectorVertex eighthSimplexVector; - eighthSimplexVector.push_back(FOURTH_VERTEX_HANDLE); - BOOST_CHECK( eighthSimplexVector.size() == 1 ); - typeSimplex eighthSimplex = std::make_pair(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert ( eighthSimplex.first, eighthSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, eighthSimplexVector.size(), eighthSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)4 ); - - // ++ NINETH - std::cout << " - INSERT (3,0)" << std::endl; - typeVectorVertex ninethSimplexVector; - ninethSimplexVector.push_back(FOURTH_VERTEX_HANDLE); - ninethSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( ninethSimplexVector.size() == 2 ); - typeSimplex ninethSimplex = std::make_pair(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert ( ninethSimplex.first, ninethSimplex.second ); - - test_simplex_tree_insert_returns_true(returnValue); - set_and_test_simplex_tree_dim_fil(st, ninethSimplexVector.size(), ninethSimplex.second); - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented !! - - // ++ TENTH - std::cout << " - INSERT 0 (already inserted)" << std::endl; - typeVectorVertex tenthSimplexVector; - tenthSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( tenthSimplexVector.size() == 1 ); - typeSimplex tenthSimplex = std::make_pair(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value - returnValue = - st.insert ( tenthSimplex.first, tenthSimplex.second ); - - BOOST_CHECK(returnValue.second == false); - typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented !! - BOOST_CHECK( st.dimension() == dim_max ); - BOOST_CHECK( AreAlmostTheSame(st.filtration(), max_fil) ); - - // ++ ELEVENTH - std::cout << " - INSERT (2,1,0) (already inserted)" << std::endl; - typeVectorVertex eleventhSimplexVector; - eleventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); - eleventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); - eleventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( eleventhSimplexVector.size() == 3 ); - typeSimplex eleventhSimplex = std::make_pair(eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); - returnValue = - st.insert ( eleventhSimplex.first, eleventhSimplex.second ); - - BOOST_CHECK(returnValue.second == false); - shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented !! - BOOST_CHECK( st.dimension() == dim_max ); - BOOST_CHECK( AreAlmostTheSame(st.filtration(), max_fil) ); - - // 1 - // o - // /X\ - // o---o---o - // 2 0 3 - - // [0.1] 0 - // [0.1] 1 - // [0.1] 2 - // [0.1] 3 - // [0.2] 1 0 - // [0.2] 2 0 - // [0.2] 2 1 - // [0.2] 3 0 - // [0.3] 2 1 0 - - // !! Be careful, simplex are sorted by filtration value on insertion !! - std::cout << "simplex_tree_insertion - first - 0" << std::endl; - test_simplex_tree_contains(st, firstSimplex, 0); // (0) -> 0 - std::cout << "simplex_tree_insertion - second - 1" << std::endl; - test_simplex_tree_contains(st, secondSimplex, 1); // (1) -> 1 - std::cout << "simplex_tree_insertion - third - 4" << std::endl; - test_simplex_tree_contains(st, thirdSimplex, 4); // (0,1) -> 4 - std::cout << "simplex_tree_insertion - fourth - 2" << std::endl; - test_simplex_tree_contains(st, fourthSimplex, 2); // (2) -> 2 - std::cout << "simplex_tree_insertion - fifth - 5" << std::endl; - test_simplex_tree_contains(st, fifthSimplex, 5); // (2,0) -> 5 - std::cout << "simplex_tree_insertion - sixth - 6" << std::endl; - test_simplex_tree_contains(st, sixthSimplex, 6); //(2,1) -> 6 - std::cout << "simplex_tree_insertion - seventh - 8" << std::endl; - test_simplex_tree_contains(st, seventhSimplex, 8); // (2,1,0) -> 8 - std::cout << "simplex_tree_insertion - eighth - 3" << std::endl; - test_simplex_tree_contains(st, eighthSimplex, 3); // (3) -> 3 - std::cout << "simplex_tree_insertion - nineth - 7" << std::endl; - test_simplex_tree_contains(st, ninethSimplex, 7); // (3,0) -> 7 - - // Display the Simplex_tree - Can not be done in the middle of 2 inserts - std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; - std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - 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 << (int)vertex << " "; - } - std::cout << std::endl; - } - -} diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp new file mode 100644 index 00000000..a3671f56 --- /dev/null +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -0,0 +1,400 @@ +#define BOOST_TEST_MODULE const_string test +#include +#include +#include +#include +#include + +#include // std::pair, std::make_pair + +#include // float comparison +#include + +#include "gudhi/graph_simplicial_complex.h" +#include "gudhi/reader_utils.h" +#include "gudhi/Simplex_tree.h" + + +using namespace Gudhi; + +typedef Simplex_tree<> typeST; +typedef std::pair< typeST::Simplex_handle, bool > typePairSimplexBool; +typedef std::vector< Vertex_handle > typeVectorVertex; +typedef std::pair typeSimplex; + +const Vertex_handle DEFAULT_VERTEX_HANDLE = (const Vertex_handle)-1; + +void test_empty_simplex_tree(typeST& tst) +{ + BOOST_CHECK( tst.null_vertex() == DEFAULT_VERTEX_HANDLE ); + BOOST_CHECK( tst.filtration() == Filtration_value(0) ); + BOOST_CHECK( tst.num_vertices() == (size_t)0 ); + BOOST_CHECK( tst.num_simplices() == (size_t)0 ); + typeST::Siblings* STRoot = tst.root(); + BOOST_CHECK( STRoot != NULL ); + BOOST_CHECK( STRoot->oncles() == NULL ); + BOOST_CHECK( STRoot->parent() == DEFAULT_VERTEX_HANDLE ); + BOOST_CHECK( tst.dimension() == -1 ); +} + +void test_iterators_on_empty_simplex_tree(typeST& tst) +{ + std::cout << "Iterator on vertices: " << std::endl; + for( auto vertex : tst.complex_vertex_range() ) + { + std::cout << "vertice:" << vertex << std::endl; + BOOST_CHECK( false); // shall be empty + } + std::cout << "Iterator on simplices: " << std::endl; + for( auto simplex : tst.complex_simplex_range() ) + { + BOOST_CHECK( false); // shall be empty + } + + std::cout << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + for( auto f_simplex : tst.filtration_simplex_range() ) + { + BOOST_CHECK( false); // shall be empty + std::cout << "test_simplex_tree_contains - filtration=" << tst.filtration(f_simplex) << std::endl; + } +} + +BOOST_AUTO_TEST_CASE( simplex_tree_when_empty ) +{ + const Filtration_value DEFAULT_FILTRATION_VALUE = 0; + + // TEST OF DEFAULT CONSTRUCTOR + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF DEFAULT CONSTRUCTOR" << std::endl; + typeST st; + + test_empty_simplex_tree(st); + + test_iterators_on_empty_simplex_tree(st); + // TEST OF EMPTY INSERTION + std::cout << "TEST OF EMPTY INSERTION" << std::endl; + typeVectorVertex simplexVectorEmpty; + BOOST_CHECK(simplexVectorEmpty.empty() == true); + typePairSimplexBool returnEmptyValue = st.insert ( simplexVectorEmpty, DEFAULT_FILTRATION_VALUE ); + BOOST_CHECK(returnEmptyValue.first == typeST::Simplex_handle(NULL)); + BOOST_CHECK(returnEmptyValue.second == true); + + test_empty_simplex_tree(st); + + test_iterators_on_empty_simplex_tree(st); +} + +bool AreAlmostTheSame(float a, float b) +{ + return std::fabs(a - b) < std::numeric_limits::epsilon(); +} + +BOOST_AUTO_TEST_CASE( simplex_tree_from_file ) +{ + // TEST OF INSERTION + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF SIMPLEX TREE FROM A FILE" << std::endl; + typeST st; + + std::string inputFile("simplex_tree_for_unit_test.txt"); + std::ifstream simplex_tree_stream(inputFile.c_str()); + simplex_tree_stream >> st; + + // Display the Simplex_tree + std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; + std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; + + // Check + BOOST_CHECK(st.num_simplices() == 143353); + BOOST_CHECK(st.dimension() == 3); + BOOST_CHECK(st.filtration() == 0.4); + + int previous_size=0; + for( auto f_simplex : st.filtration_simplex_range() ) + { + // Size of simplex + int size=0; + for( auto vertex : st.simplex_vertex_range(f_simplex) ) + { + size++; + } + BOOST_CHECK(AreAlmostTheSame(st.filtration(f_simplex),(0.1* size))); // Specific test: filtration = 0.1 * simplex_size + BOOST_CHECK(previous_size <= size); // Check list is sorted (because of sorted filtrations in simplex_tree.txt) + previous_size = size; + } + simplex_tree_stream.close(); +} + +void test_simplex_tree_contains(typeST& simplexTree, typeSimplex simplex, int pos) +{ + auto f_simplex = simplexTree.filtration_simplex_range().begin(); + f_simplex += pos; + std::cout << "test_simplex_tree_contains - filtration=" << simplexTree.filtration(*f_simplex) << "||" << simplex.second << std::endl; + BOOST_CHECK( AreAlmostTheSame(simplexTree.filtration(*f_simplex),simplex.second) ); + + typeVectorVertex::iterator simplexIter = simplex.first.end()-1; + for( auto vertex : simplexTree.simplex_vertex_range(*f_simplex) ) + { + std::cout << "test_simplex_tree_contains - vertex=" << vertex << "||" << *simplexIter << std::endl; + BOOST_CHECK( vertex == *simplexIter); + simplexIter--; + } +} + +void test_simplex_tree_insert_returns_true(const typePairSimplexBool& returnValue) +{ + BOOST_CHECK(returnValue.second == true); + typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + BOOST_CHECK(shReturned != typeST::Simplex_handle(NULL)); +} + +// Global variables +Filtration_value max_fil = 0.0; +int dim_max = -1; + +void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, const Filtration_value& fil) +{ + if (vectorSize > dim_max+1) + { + dim_max = vectorSize-1; + simplexTree.set_dimension(dim_max); + std::cout << " set_and_test_simplex_tree_dim_fil - dim_max=" << dim_max << std::endl; + } + if (fil > max_fil) + { + max_fil = fil; + simplexTree.set_filtration(max_fil); + std::cout << " set_and_test_simplex_tree_dim_fil - max_fil=" << max_fil << std::endl; + } + int nb_simplices = simplexTree.num_simplices() + 1; + simplexTree.set_num_simplices(nb_simplices); + + BOOST_CHECK( simplexTree.dimension() == dim_max ); + BOOST_CHECK( AreAlmostTheSame(simplexTree.filtration(), max_fil) ); + BOOST_CHECK( simplexTree.num_simplices() == nb_simplices ); +} + +BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) +{ + const Filtration_value FIRST_FILTRATION_VALUE = 0.1; + const Filtration_value SECOND_FILTRATION_VALUE = 0.2; + const Filtration_value THIRD_FILTRATION_VALUE = 0.3; + const Filtration_value FOURTH_FILTRATION_VALUE = 0.4; + Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle)0; + Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle)1; + Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle)2; + Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle)3; + + // TEST OF INSERTION + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF INSERTION" << std::endl; + typeST st; + + // ++ FIRST + std::cout << " - INSERT 0" << std::endl; + typeVectorVertex firstSimplexVector; + firstSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( firstSimplexVector.size() == 1 ); + typeSimplex firstSimplex = std::make_pair(firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + typePairSimplexBool returnValue = + st.insert ( firstSimplex.first, firstSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, firstSimplexVector.size(), firstSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)1 ); + + // ++ SECOND + std::cout << " - INSERT 1" << std::endl; + typeVectorVertex secondSimplexVector; + secondSimplexVector.push_back(SECOND_VERTEX_HANDLE); + BOOST_CHECK( secondSimplexVector.size() == 1 ); + typeSimplex secondSimplex = std::make_pair(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = + st.insert ( secondSimplex.first, secondSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, secondSimplexVector.size(), secondSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)2 ); + + // ++ THIRD + std::cout << " - INSERT (0,1)" << std::endl; + typeVectorVertex thirdSimplexVector; + thirdSimplexVector.push_back(FIRST_VERTEX_HANDLE); + thirdSimplexVector.push_back(SECOND_VERTEX_HANDLE); + BOOST_CHECK( thirdSimplexVector.size() == 2 ); + typeSimplex thirdSimplex = std::make_pair(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = + st.insert ( thirdSimplex.first, thirdSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, thirdSimplexVector.size(), thirdSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)2 ); // Not incremented !! + + // ++ FOURTH + std::cout << " - INSERT 2" << std::endl; + typeVectorVertex fourthSimplexVector; + fourthSimplexVector.push_back(THIRD_VERTEX_HANDLE); + BOOST_CHECK( fourthSimplexVector.size() == 1 ); + typeSimplex fourthSimplex = std::make_pair(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = + st.insert ( fourthSimplex.first, fourthSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, fourthSimplexVector.size(), fourthSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)3 ); + + // ++ FIFTH + std::cout << " - INSERT (2,0)" << std::endl; + typeVectorVertex fifthSimplexVector; + fifthSimplexVector.push_back(THIRD_VERTEX_HANDLE); + fifthSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( fifthSimplexVector.size() == 2 ); + typeSimplex fifthSimplex = std::make_pair(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = + st.insert ( fifthSimplex.first, fifthSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, fifthSimplexVector.size(), fifthSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)3 ); // Not incremented !! + + // ++ SIXTH + std::cout << " - INSERT (2,1)" << std::endl; + typeVectorVertex sixthSimplexVector; + sixthSimplexVector.push_back(THIRD_VERTEX_HANDLE); + sixthSimplexVector.push_back(SECOND_VERTEX_HANDLE); + BOOST_CHECK( sixthSimplexVector.size() == 2 ); + typeSimplex sixthSimplex = std::make_pair(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = + st.insert ( sixthSimplex.first, sixthSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, sixthSimplexVector.size(), sixthSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)3 ); // Not incremented !! + + // ++ SEVENTH + std::cout << " - INSERT (2,1,0)" << std::endl; + typeVectorVertex seventhSimplexVector; + seventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); + seventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); + seventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( seventhSimplexVector.size() == 3 ); + typeSimplex seventhSimplex = std::make_pair(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); + returnValue = + st.insert ( seventhSimplex.first, seventhSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, seventhSimplexVector.size(), seventhSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)3 ); // Not incremented !! + + // ++ EIGHTH + std::cout << " - INSERT 3" << std::endl; + typeVectorVertex eighthSimplexVector; + eighthSimplexVector.push_back(FOURTH_VERTEX_HANDLE); + BOOST_CHECK( eighthSimplexVector.size() == 1 ); + typeSimplex eighthSimplex = std::make_pair(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = + st.insert ( eighthSimplex.first, eighthSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, eighthSimplexVector.size(), eighthSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)4 ); + + // ++ NINETH + std::cout << " - INSERT (3,0)" << std::endl; + typeVectorVertex ninethSimplexVector; + ninethSimplexVector.push_back(FOURTH_VERTEX_HANDLE); + ninethSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( ninethSimplexVector.size() == 2 ); + typeSimplex ninethSimplex = std::make_pair(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = + st.insert ( ninethSimplex.first, ninethSimplex.second ); + + test_simplex_tree_insert_returns_true(returnValue); + set_and_test_simplex_tree_dim_fil(st, ninethSimplexVector.size(), ninethSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented !! + + // ++ TENTH + std::cout << " - INSERT 0 (already inserted)" << std::endl; + typeVectorVertex tenthSimplexVector; + tenthSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( tenthSimplexVector.size() == 1 ); + typeSimplex tenthSimplex = std::make_pair(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value + returnValue = + st.insert ( tenthSimplex.first, tenthSimplex.second ); + + BOOST_CHECK(returnValue.second == false); + typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); + BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented !! + BOOST_CHECK( st.dimension() == dim_max ); + BOOST_CHECK( AreAlmostTheSame(st.filtration(), max_fil) ); + + // ++ ELEVENTH + std::cout << " - INSERT (2,1,0) (already inserted)" << std::endl; + typeVectorVertex eleventhSimplexVector; + eleventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); + eleventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); + eleventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( eleventhSimplexVector.size() == 3 ); + typeSimplex eleventhSimplex = std::make_pair(eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); + returnValue = + st.insert ( eleventhSimplex.first, eleventhSimplex.second ); + + BOOST_CHECK(returnValue.second == false); + shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); + BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented !! + BOOST_CHECK( st.dimension() == dim_max ); + BOOST_CHECK( AreAlmostTheSame(st.filtration(), max_fil) ); + + // 1 + // o + // /X\ + // o---o---o + // 2 0 3 + + // [0.1] 0 + // [0.1] 1 + // [0.1] 2 + // [0.1] 3 + // [0.2] 1 0 + // [0.2] 2 0 + // [0.2] 2 1 + // [0.2] 3 0 + // [0.3] 2 1 0 + + // !! Be careful, simplex are sorted by filtration value on insertion !! + std::cout << "simplex_tree_insertion - first - 0" << std::endl; + test_simplex_tree_contains(st, firstSimplex, 0); // (0) -> 0 + std::cout << "simplex_tree_insertion - second - 1" << std::endl; + test_simplex_tree_contains(st, secondSimplex, 1); // (1) -> 1 + std::cout << "simplex_tree_insertion - third - 4" << std::endl; + test_simplex_tree_contains(st, thirdSimplex, 4); // (0,1) -> 4 + std::cout << "simplex_tree_insertion - fourth - 2" << std::endl; + test_simplex_tree_contains(st, fourthSimplex, 2); // (2) -> 2 + std::cout << "simplex_tree_insertion - fifth - 5" << std::endl; + test_simplex_tree_contains(st, fifthSimplex, 5); // (2,0) -> 5 + std::cout << "simplex_tree_insertion - sixth - 6" << std::endl; + test_simplex_tree_contains(st, sixthSimplex, 6); //(2,1) -> 6 + std::cout << "simplex_tree_insertion - seventh - 8" << std::endl; + test_simplex_tree_contains(st, seventhSimplex, 8); // (2,1,0) -> 8 + std::cout << "simplex_tree_insertion - eighth - 3" << std::endl; + test_simplex_tree_contains(st, eighthSimplex, 3); // (3) -> 3 + std::cout << "simplex_tree_insertion - nineth - 7" << std::endl; + test_simplex_tree_contains(st, ninethSimplex, 7); // (3,0) -> 7 + + // Display the Simplex_tree - Can not be done in the middle of 2 inserts + std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; + std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; + std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + 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 << (int)vertex << " "; + } + std::cout << std::endl; + } + +} -- cgit v1.2.3