summaryrefslogtreecommitdiff
path: root/src/Skeleton_blocker
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-09-16 14:34:07 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-09-16 14:34:07 +0000
commit63f15e8f3cab97b12539ad82c4423de6d361204a (patch)
tree2ad228f3135e6a457feafd7f8d3572846dace0ee /src/Skeleton_blocker
parentef4ee52fdc6c52629c8c3959c7a15b5280a40373 (diff)
Rewrite tests wit BOOST tests
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/warning_fix@1506 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5afe034e18381c4921987457fd75f15c21b3aed1
Diffstat (limited to 'src/Skeleton_blocker')
-rw-r--r--src/Skeleton_blocker/test/TestGeometricComplex.cpp83
-rw-r--r--src/Skeleton_blocker/test/TestSimplifiable.cpp277
-rw-r--r--src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp540
3 files changed, 373 insertions, 527 deletions
diff --git a/src/Skeleton_blocker/test/TestGeometricComplex.cpp b/src/Skeleton_blocker/test/TestGeometricComplex.cpp
index c5351b04..d035b2c3 100644
--- a/src/Skeleton_blocker/test/TestGeometricComplex.cpp
+++ b/src/Skeleton_blocker/test/TestGeometricComplex.cpp
@@ -25,9 +25,13 @@
#include <string>
#include <fstream>
#include <sstream>
-#include <gudhi/Test.h>
-#include <gudhi/Skeleton_blocker.h>
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "skeleton_blocker_geometric_complex"
+#include <boost/test/unit_test.hpp>
+#include <boost/mpl/list.hpp>
+
+#include <gudhi/Skeleton_blocker.h>
struct Geometry_trait {
typedef std::vector<double> Point;
@@ -37,24 +41,22 @@ typedef Geometry_trait::Point Point;
typedef Gudhi::skeleton_blocker::Skeleton_blocker_simple_geometric_traits<Geometry_trait> Complex_geometric_traits;
typedef Gudhi::skeleton_blocker::Skeleton_blocker_geometric_complex< Complex_geometric_traits > Complex;
typedef Complex::Vertex_handle Vertex_handle;
+typedef Complex_geometric_traits::Root_vertex_handle Root_vertex_handle;
-bool test_constructor1() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_off_reader_writer) {
Complex complex;
Gudhi::skeleton_blocker::Skeleton_blocker_off_reader<Complex> off_reader("test2.off", complex);
- if (!off_reader.is_valid()) {
- std::cerr << "Unable to read file" << std::endl;
- return false;
- }
-
-
+ BOOST_CHECK(off_reader.is_valid());
+
std::cout << "complex has " <<
complex.num_vertices() << " vertices, " <<
complex.num_blockers() << " blockers, " <<
- complex.num_edges() << " edges and" <<
+ complex.num_edges() << " edges and " <<
complex.num_triangles() << " triangles.";
- if (complex.num_vertices() != 7 || complex.num_edges() != 12 || complex.num_triangles() != 6)
- return false;
+ BOOST_CHECK(complex.num_vertices() == 7);
+ BOOST_CHECK(complex.num_edges() == 12);
+ BOOST_CHECK(complex.num_triangles() == 6);
Gudhi::skeleton_blocker::Skeleton_blocker_off_writer<Complex> off_writer("tmp.off", complex);
Complex same;
@@ -63,31 +65,47 @@ bool test_constructor1() {
std::cout << "\ncomplex:" << complex.to_string() << std::endl;
std::cout << "\nsame:" << same.to_string() << std::endl;
- return (complex == same);
+ BOOST_CHECK(complex == same);
}
-bool test_constructor2() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_abstract_link) {
Complex complex;
Gudhi::skeleton_blocker::Skeleton_blocker_off_reader<Complex> off_reader("test2.off", complex);
- if (!off_reader.is_valid()) {
- std::cerr << "Unable to read file" << std::endl;
- return false;
- }
+ BOOST_CHECK(off_reader.is_valid());
+
std::cout << "complex has " <<
complex.num_vertices() << " vertices, " <<
complex.num_blockers() << " blockers, " <<
- complex.num_edges() << " edges and" <<
+ complex.num_edges() << " edges and " <<
complex.num_triangles() << " triangles.";
- if (complex.num_vertices() != 7 || complex.num_edges() != 12 || complex.num_triangles() != 6)
- return false;
+ BOOST_CHECK(complex.num_vertices() == 7);
+ BOOST_CHECK(complex.num_edges() == 12);
+ BOOST_CHECK(complex.num_triangles() == 6);
auto link_0 = complex.abstract_link(Vertex_handle(0));
-
std::cout << "\n link(0):" << link_0.to_string() << std::endl;
+ BOOST_CHECK(link_0.num_vertices() == 2);
+ BOOST_CHECK(link_0.num_edges() == 1);
+ BOOST_CHECK(link_0.num_blockers() == 0);
+
+ // Check the 2 link vertices
+ auto vertex_handle = link_0.vertex_range().begin();
+ BOOST_CHECK(link_0[*vertex_handle].get_id() == Root_vertex_handle(1));
+ vertex_handle++;
+ BOOST_CHECK(link_0[*(vertex_handle)].get_id() == Root_vertex_handle(4));
+
+ // Check the lonely link edge
+ auto edge_handle = link_0.edge_range().begin();
+ BOOST_CHECK(link_0[*edge_handle].first() == Root_vertex_handle(1));
+ BOOST_CHECK(link_0[*(edge_handle)].second() == Root_vertex_handle(4));
+
auto link_geometric_0 = complex.link(Vertex_handle(0));
+ std::cout << "\n link_geometric(0):" << link_geometric_0.to_string() << std::endl;
+
+ BOOST_CHECK(link_0 == link_geometric_0);
auto print_point = [&](Vertex_handle v) {
for (auto x : link_geometric_0.point(v)) std::cout << x << " ";
@@ -96,19 +114,12 @@ bool test_constructor2() {
std::for_each(link_geometric_0.vertex_range().begin(), link_geometric_0.vertex_range().end(), print_point);
- // for(auto v : link_geometric_0.vertex_range())
- // std::cout<<"point("<<v<<"):"<<link_geometric_0.point(v)<<std::endl;
-
- return link_0.num_vertices() == 2;
-}
-
-int main(int argc, char *argv[]) {
- Tests tests_geometric_complex;
- tests_geometric_complex.add("Test constructor 1", test_constructor1);
- tests_geometric_complex.add("Test constructor 2", test_constructor2);
+ // Check the 2 link vertices
+ vertex_handle = link_geometric_0.vertex_range().begin();
+ std::vector<double> point_1 = {0,2,0};
+ std::vector<double> point_4 = {-1,1,0};
+ BOOST_CHECK(link_geometric_0.point(*vertex_handle) == point_1);
+ vertex_handle++;
+ BOOST_CHECK(link_geometric_0.point(*vertex_handle) == point_4);
- if (tests_geometric_complex.run())
- return EXIT_SUCCESS;
- else
- return EXIT_FAILURE;
}
diff --git a/src/Skeleton_blocker/test/TestSimplifiable.cpp b/src/Skeleton_blocker/test/TestSimplifiable.cpp
index b5384318..360b91db 100644
--- a/src/Skeleton_blocker/test/TestSimplifiable.cpp
+++ b/src/Skeleton_blocker/test/TestSimplifiable.cpp
@@ -25,9 +25,13 @@
#include <string>
#include <fstream>
#include <sstream>
-#include <gudhi/Test.h>
-#include <gudhi/Skeleton_blocker.h>
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "skeleton_blocker_simplifiable"
+#include <boost/test/unit_test.hpp>
+#include <boost/mpl/list.hpp>
+
+#include <gudhi/Skeleton_blocker.h>
template<typename ComplexType> class Skeleton_blocker_sub_complex;
typedef Gudhi::skeleton_blocker::Skeleton_blocker_simple_traits Traits;
@@ -35,22 +39,7 @@ typedef Gudhi::skeleton_blocker::Skeleton_blocker_complex<Traits> Complex;
typedef Complex::Vertex_handle Vertex_handle;
typedef Complex::Root_vertex_handle Root_vertex_handle;
typedef Gudhi::skeleton_blocker::Skeleton_blocker_simplex<Vertex_handle> Simplex;
-// true iff v \in complex
-
-bool assert_vertex(Complex &complex, Vertex_handle v) {
- Simplex simplex(v);
- bool test = complex.contains(simplex);
- assert(test);
- return test;
-}
-
-// true iff the blocker (a,b,c) is in complex
-bool assert_blocker(Complex &complex, Root_vertex_handle a, Root_vertex_handle b, Root_vertex_handle c) {
-
- return complex.contains_blocker(Simplex(*complex.get_address(a), *complex.get_address(b), *complex.get_address(c)));
- //return complex.contains_blocker((a),(b),(c));
-}
void build_complete(int n, Complex& complex) {
complex.clear();
@@ -61,11 +50,8 @@ void build_complete(int n, Complex& complex) {
complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j));
}
-bool test_contraction1() {
-
- enum {
- a, b, x, y, z, n
- };
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_contraction1) {
+ enum { a, b, x, y, z, n };
Complex complex(n);
build_complete(n, complex);
complex.remove_edge(static_cast<Vertex_handle> (b), static_cast<Vertex_handle> (z));
@@ -75,35 +61,35 @@ bool test_contraction1() {
static_cast<Vertex_handle> (y)));
// Print result
- std::cerr << "complex before complex" << complex.to_string() << std::endl;
+ std::cout << "complex before complex" << complex.to_string() << std::endl;
- std::cerr << std::endl << std::endl;
+ std::cout << std::endl << std::endl;
complex.contract_edge(static_cast<Vertex_handle> (a), static_cast<Vertex_handle> (b));
// Print result
- std::cerr << "ContractEdge(0,1)\n";
+ std::cout << "ContractEdge(0,1)\n";
PRINT(complex.to_string());
// verification
for (int i = 0; i < 5; i++)
- if (i != 1) assert_vertex(complex, static_cast<Vertex_handle> (i));
- bool test1 = !complex.contains_edge(static_cast<Vertex_handle> (a), static_cast<Vertex_handle> (b));
- bool test2 = assert_blocker(complex, Root_vertex_handle(a), Root_vertex_handle(x), Root_vertex_handle(y));
- bool test3 = complex.num_edges() == 6;
- bool test4 = complex.num_blockers() == 1;
+ if (i != 1) BOOST_CHECK(complex.contains(Simplex(static_cast<Vertex_handle> (i))));
+ BOOST_CHECK(!complex.contains_edge(static_cast<Vertex_handle> (a), static_cast<Vertex_handle> (b)));
+
+ BOOST_CHECK(complex.contains_blocker(Simplex(*complex.get_address(Root_vertex_handle(a)),
+ *complex.get_address(Root_vertex_handle(x)),
+ *complex.get_address(Root_vertex_handle(y)))));
+
+ BOOST_CHECK(complex.num_edges() == 6);
+ BOOST_CHECK(complex.num_blockers() == 1);
Simplex sigma;
sigma.add_vertex(static_cast<Vertex_handle> (a));
sigma.add_vertex(static_cast<Vertex_handle> (x));
sigma.add_vertex(static_cast<Vertex_handle> (y));
sigma.add_vertex(static_cast<Vertex_handle> (z));
- bool test5 = !(complex.contains(sigma));
- return test1 && test2 && test3 && test4&&test5;
+ BOOST_CHECK(!(complex.contains(sigma)));
}
-bool test_contraction2() {
-
- enum {
- a, b, x, y, z, n
- };
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_contraction2) {
+ enum { a, b, x, y, z, n };
Complex complex(n);
build_complete(n, complex);
complex.remove_edge(static_cast<Vertex_handle> (b), static_cast<Vertex_handle> (x));
@@ -115,83 +101,73 @@ bool test_contraction2() {
complex.add_blocker(blocker);
// Print result
- std::cerr << "complex complex" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "complex complex" << complex.to_string();
+ std::cout << std::endl << std::endl;
complex.contract_edge(static_cast<Vertex_handle> (a), static_cast<Vertex_handle> (b));
- std::cerr << "complex.ContractEdge(a,b)" << complex.to_string();
+ std::cout << "complex.ContractEdge(a,b)" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << std::endl << std::endl;
// there should be one blocker (a,c,d,e) in the complex
- bool test;
- test = complex.contains_blocker(Simplex(static_cast<Vertex_handle> (a), static_cast<Vertex_handle> (x),
- static_cast<Vertex_handle> (y), static_cast<Vertex_handle> (z)));
- test = test && complex.num_blockers() == 1;
- return test;
+ BOOST_CHECK(complex.contains_blocker(Simplex(static_cast<Vertex_handle> (a), static_cast<Vertex_handle> (x),
+ static_cast<Vertex_handle> (y), static_cast<Vertex_handle> (z))));
+ BOOST_CHECK(complex.num_blockers() == 1);
}
-bool test_link_condition1() {
-
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_link_condition1) {
Complex complex(0);
// Build the complexes
build_complete(4, complex);
complex.add_blocker(Simplex(static_cast<Vertex_handle> (0), static_cast<Vertex_handle> (1), static_cast<Vertex_handle> (2)));
-
// Print result
- std::cerr << "complex complex" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "complex complex" << complex.to_string();
+ std::cout << std::endl << std::endl;
- bool weak_link_condition = complex.link_condition(Vertex_handle(1), Vertex_handle(2), true);
+ BOOST_CHECK(complex.link_condition(Vertex_handle(1), Vertex_handle(2), true));
- bool strong_link_condition = complex.link_condition(Vertex_handle(1), Vertex_handle(2), false);
-
- return weak_link_condition && !strong_link_condition;
+ BOOST_CHECK(!complex.link_condition(Vertex_handle(1), Vertex_handle(2), false));
}
-bool test_collapse0() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_collapse0) {
Complex complex(5);
build_complete(4, complex);
complex.add_vertex();
complex.add_edge_without_blockers(static_cast<Vertex_handle> (2), static_cast<Vertex_handle> (4));
complex.add_edge_without_blockers(static_cast<Vertex_handle> (3), static_cast<Vertex_handle> (4));
// Print result
- std::cerr << "initial complex :\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "initial complex :\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
Simplex simplex_123(static_cast<Vertex_handle> (1), static_cast<Vertex_handle> (2), static_cast<Vertex_handle> (3));
complex.remove_star(simplex_123);
- std::cerr << "complex.remove_star(1,2,3):\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "complex.remove_star(1,2,3):\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
// verification
- bool blocker123_here = complex.contains_blocker(simplex_123);
- std::cerr << "----> Ocomplex \n";
- return blocker123_here;
+ BOOST_CHECK(complex.contains_blocker(simplex_123));
}
-bool test_collapse1() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_collapse1) {
Complex complex(5);
build_complete(4, complex);
complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)));
// Print result
- std::cerr << "initial complex :\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "initial complex :\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
Simplex simplex_123(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3));
complex.remove_star(simplex_123);
- std::cerr << "complex.remove_star(1,2,3):\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "complex.remove_star(1,2,3):\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
// verification
- bool res = complex.contains_blocker(simplex_123);
- res = res && complex.num_blockers() == 1;
- std::cerr << "----> Ocomplex \n";
- return res;
+ BOOST_CHECK(complex.contains_blocker(simplex_123));
+ BOOST_CHECK(complex.num_blockers() == 1);
}
-bool test_collapse2() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_collapse2) {
Complex complex(5);
build_complete(4, complex);
complex.add_vertex();
@@ -200,21 +176,21 @@ bool test_collapse2() {
complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4));
complex.add_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3), Vertex_handle(4)));
// Print result
- std::cerr << "initial complex :\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "initial complex :\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
Simplex sigma(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3));
complex.remove_star(sigma);
- std::cerr << "complex.remove_star(1,2,3):\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "complex.remove_star(1,2,3):\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
// verification
- bool blocker_removed = !complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3), Vertex_handle(4)));
- bool blocker123_here = complex.contains_blocker(sigma);
- return blocker_removed && blocker123_here;
+ BOOST_CHECK(!complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2),
+ Vertex_handle(3), Vertex_handle(4))));
+ BOOST_CHECK(complex.contains_blocker(sigma));
}
-bool test_collapse3() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_collapse3) {
Complex complex(5);
build_complete(4, complex);
complex.add_vertex();
@@ -223,36 +199,37 @@ bool test_collapse3() {
complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4));
complex.add_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3), Vertex_handle(4)));
// Print result
- std::cerr << "initial complex:\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "initial complex:\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
complex.remove_star(static_cast<Vertex_handle> (2));
- std::cerr << "complex after remove star of 2:\n" << complex.to_string();
+ std::cout << "complex after remove star of 2:\n" << complex.to_string();
- bool blocker134_here = complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(3), Vertex_handle(4)));
- bool blocker1234_here = complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3), Vertex_handle(4)));
- return blocker134_here && !blocker1234_here;
+ BOOST_CHECK(complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(3), Vertex_handle(4))));
+ BOOST_CHECK(!complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2),
+ Vertex_handle(3), Vertex_handle(4))));
}
-bool test_add_simplex() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_add_simplex) {
Complex complex(4);
build_complete(4, complex);
complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(3)));
- std::cerr << "initial complex:\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "initial complex:\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
complex.add_simplex(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(3)));
- std::cerr << "complex after add_simplex:\n" << complex.to_string();
- return complex.num_blockers() == 1
- && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)));
+ std::cout << "complex after add_simplex:\n" << complex.to_string();
+ BOOST_CHECK(complex.num_blockers() == 1);
+ BOOST_CHECK(complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1),
+ Vertex_handle(2), Vertex_handle(3))));
}
-bool test_add_simplex2() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_add_simplex2) {
Complex complex;
build_complete(4, complex);
// Print result
- std::cerr << "initial complex:\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "initial complex:\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
Complex copy(complex.num_vertices());
@@ -267,33 +244,33 @@ bool test_add_simplex2() {
copy.add_simplex(simplex);
}
+ std::cout << "complex after add_simplex:\n" << copy.to_string();
- std::cerr << "complex after add_simplex:\n" << copy.to_string();
-
-
- return complex.num_blockers() == copy.num_blockers() &&
- complex.num_edges() == copy.num_edges() &&
- complex.num_vertices() == copy.num_vertices();
+ BOOST_CHECK(complex.num_blockers() == copy.num_blockers());
+ BOOST_CHECK(complex.num_edges() == copy.num_edges());
+ BOOST_CHECK(complex.num_vertices() == copy.num_vertices());
}
-bool test_add_simplex3() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_add_simplex3) {
Complex complex(5);
build_complete(5, complex);
complex.remove_edge(Vertex_handle(3), Vertex_handle(4));
Simplex sigma(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2));
complex.add_blocker(sigma);
// Print result
- std::cerr << "initial complex:\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "initial complex:\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
complex.add_simplex(sigma);
//should create two blockers 0123 and 0124
- std::cerr << "complex after adding simplex 012:\n" << complex.to_string();
- return complex.num_blockers() == 2
- && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)))
- && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(4)));
+ std::cout << "complex after adding simplex 012:\n" << complex.to_string();
+ BOOST_CHECK(complex.num_blockers() == 2);
+ BOOST_CHECK(complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1),
+ Vertex_handle(2), Vertex_handle(3))));
+ BOOST_CHECK(complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1),
+ Vertex_handle(2), Vertex_handle(4))));
}
-bool test_add_simplex4() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_add_simplex4) {
int n = 6;
Complex complex(n);
@@ -306,40 +283,38 @@ bool test_add_simplex4() {
complex.add_simplex(s);
//at step i there is only blocker 0..i
- if (i < 2 && complex.num_blockers() > 0)
- return false;
+ BOOST_CHECK(!(i < 2 && complex.num_blockers() > 0));
if (i >= 2 && complex.num_blockers() != 1) {
Simplex b;
for (int k = 0; k < i; k++)
b.add_vertex(Vertex_handle(i));
- if (!complex.contains_blocker(b))
- return false;
+ BOOST_CHECK(complex.contains_blocker(b));
}
- TESTVALUE(complex.blockers_to_string());
}
Simplex s;
for (int k = 0; k < n; k++)
s.add_vertex(Vertex_handle(k));
- return complex.num_blockers() == 1 && complex.contains_blocker(s);
+ BOOST_CHECK(complex.num_blockers() == 1);
+ BOOST_CHECK(complex.contains_blocker(s));
}
-bool test_add_edge() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_add_edge) {
Complex complex(4);
for (unsigned i = 0u; i < 4; i++)
complex.add_edge(Vertex_handle(i), Vertex_handle((i + 1) % 4));
// Print result
- std::cerr << "initial complex:\n" << complex.to_string();
- std::cerr << std::endl << std::endl;
+ std::cout << "initial complex:\n" << complex.to_string();
+ std::cout << std::endl << std::endl;
complex.add_edge(Vertex_handle(1), Vertex_handle(3));
//should create two blockers 013 and 012
- std::cerr << "complex after adding edge 13:\n" << complex.to_string();
- return complex.num_blockers() == 2
- && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(3)))
- && complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)));
+ std::cout << "complex after adding edge 13:\n" << complex.to_string();
+ BOOST_CHECK(complex.num_blockers() == 2);
+ BOOST_CHECK(complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(3))));
+ BOOST_CHECK(complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))));
}
-bool test_remove_popable_blockers() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplifiable_remove_popable_blockers) {
Complex complex;
build_complete(4, complex);
complex.add_vertex();
@@ -350,15 +325,14 @@ bool test_remove_popable_blockers() {
complex.add_blocker(sigma1);
complex.add_blocker(sigma2);
- std::cerr << "complex complex" << complex.to_string();
- std::cerr << std::endl << std::endl;
- std::cerr << "complex.RemovePopableBlockers();" << std::endl;
+ std::cout << "complex complex" << complex.to_string();
+ std::cout << std::endl << std::endl;
+ std::cout << "complex.RemovePopableBlockers();" << std::endl;
complex.remove_popable_blockers();
- std::cerr << "complex complex" << complex.to_string();
- std::cerr << std::endl << std::endl;
-
- bool test1 = (complex.num_blockers() == 1);
+ std::cout << "complex complex" << complex.to_string();
+ std::cout << std::endl << std::endl;
+ BOOST_CHECK(complex.num_blockers() == 1);
// test 2
complex.clear();
@@ -375,41 +349,12 @@ bool test_remove_popable_blockers() {
complex.add_blocker(sigma1);
complex.add_blocker(sigma2);
- std::cerr << "complex complex" << complex.to_string();
- std::cerr << std::endl << std::endl;
- std::cerr << "complex.RemovePopableBlockers();" << std::endl;
+ std::cout << "complex complex" << complex.to_string();
+ std::cout << std::endl << std::endl;
+ std::cout << "complex.RemovePopableBlockers();" << std::endl;
complex.remove_popable_blockers();
- std::cerr << "complex complex" << complex.to_string();
-
- std::cerr << std::endl << std::endl;
- bool test2 = (complex.num_blockers() == 0);
- return test1&&test2;
-}
-
-int main(int argc, char *argv[]) {
- Tests tests_simplifiable_complex;
- tests_simplifiable_complex.add("Test contraction 1", test_contraction1);
- tests_simplifiable_complex.add("Test contraction 2", test_contraction2);
- tests_simplifiable_complex.add("Test Link condition 1", test_link_condition1);
- tests_simplifiable_complex.add("Test remove popable blockers", test_remove_popable_blockers);
-
-
- tests_simplifiable_complex.add("Test collapse 0", test_collapse0);
- tests_simplifiable_complex.add("Test collapse 1", test_collapse1);
- tests_simplifiable_complex.add("Test collapse 2", test_collapse2);
- tests_simplifiable_complex.add("Test collapse 3", test_collapse3);
-
- tests_simplifiable_complex.add("Test add edge", test_add_edge);
- tests_simplifiable_complex.add("Test add simplex", test_add_simplex);
- tests_simplifiable_complex.add("Test add simplex2", test_add_simplex2);
- tests_simplifiable_complex.add("Test add simplex3", test_add_simplex3);
- tests_simplifiable_complex.add("Test add simplex4", test_add_simplex4);
-
-
- tests_simplifiable_complex.run();
+ std::cout << "complex complex" << complex.to_string();
- if (tests_simplifiable_complex.run())
- return EXIT_SUCCESS;
- else
- return EXIT_FAILURE;
+ std::cout << std::endl << std::endl;
+ BOOST_CHECK(complex.num_blockers() == 0);
}
diff --git a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp
index c74f591e..f94c756e 100644
--- a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp
+++ b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp
@@ -24,8 +24,12 @@
#include <string>
#include <fstream>
#include <sstream>
-#include <gudhi/Debug_utils.h>
-#include <gudhi/Test.h>
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "skeleton_blocker_complex"
+#include <boost/test/unit_test.hpp>
+#include <boost/mpl/list.hpp>
+
#include <gudhi/Skeleton_blocker.h>
template<typename ComplexType> class Skeleton_blocker_sub_complex;
@@ -39,8 +43,6 @@ typedef Complex::Root_simplex_handle Root_simplex_handle;
typedef Simplex::Simplex_vertex_const_iterator Simplex_vertex_const_iterator;
typedef Complex::Edge_handle Edge_handle;
-// true if v in complex
-
bool assert_vertex(Complex &complex, Vertex_handle v) {
//assert(complex.contains(v));
return complex.contains(static_cast<Simplex> (v));
@@ -72,75 +74,59 @@ void build_complete(int n, Complex& complex) {
for (int i = 0; i < n; i++)
complex.add_vertex();
- // for(int i=n-1;i>=0;i--)
- // for(int j=i-1;j>=0;j--)
- // complex.add_edge_without_blockers(Vertex_handle(i),Vertex_handle(j));
-
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++)
complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j));
}
-bool test_simplex() {
- // PRINT("test simplex");
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_simplex) {
Simplex simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3));
- for (auto i = simplex.begin(); i != simplex.end(); ++i) {
- PRINT(*i);
- auto j = i;
- for (++j;
- j != simplex.end();
- ++j) {
- PRINT(*j);
- }
- }
- return simplex.dimension() == 3;
+ BOOST_CHECK(simplex.dimension() == 3);
}
-bool test_num_simplices() {
+BOOST_AUTO_TEST_CASE(test_skeleton_num_simplices) {
int n = 4;
Complex complex;
build_complete(n, complex);
size_t sum = 0;
for (int i = 0; i < n; i++) {
- PRINT(complex.num_simplices(i));
sum += complex.num_simplices(i);
}
- return
- complex.num_vertices() == n &&
- complex.num_edges() == 6 &&
- sum == 15 &&
- complex.num_simplices() == 15;
+ BOOST_CHECK(complex.num_vertices() == n);
+ BOOST_CHECK(complex.num_edges() == 6);
+ BOOST_CHECK(sum == 15);
+ BOOST_CHECK(complex.num_simplices() == 15);
}
-bool test_iterator_vertices1() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_vertices1) {
int n = 10;
Complex complex(10);
- std::cerr << "complex.num_vertices():" << complex.num_vertices() << std::endl;
+ std::cout << "complex.num_vertices():" << complex.num_vertices() << std::endl;
int num_vertex_seen = 0;
for (auto vi : complex.vertex_range()) {
- std::cerr << "vertex:" << vi << std::endl;
+ std::cout << "vertex:" << vi << std::endl;
++num_vertex_seen;
}
- return num_vertex_seen == n;
+ BOOST_CHECK(num_vertex_seen == n);
}
-bool test_iterator_vertices2() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_vertices2) {
int n = 10;
Complex complex;
build_complete(10, complex);
- std::cerr << "complex.num_vertices():" << complex.num_vertices() << std::endl;
- std::cerr << "complex.num_edges():" << complex.num_edges() << std::endl;
+ std::cout << "complex.num_vertices():" << complex.num_vertices() << std::endl;
+ std::cout << "complex.num_edges():" << complex.num_edges() << std::endl;
int num_vertex_seen = 0;
for (auto vi : complex.vertex_range(Vertex_handle(2))) {
- std::cerr << "vertex:" << vi << std::endl;
+ std::cout << "vertex:" << vi << std::endl;
++num_vertex_seen;
}
- std::cerr << "num_vertex_seen:" << num_vertex_seen << std::endl;
- return num_vertex_seen == (n - 1);
+ std::cout << "num_vertex_seen:" << num_vertex_seen << std::endl;
+ BOOST_CHECK(num_vertex_seen == (n -1));
}
-bool test_iterator_edge() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_edge) {
const int n = 10;
Complex complex(n);
for (int i = 0; i < n; i++)
@@ -148,17 +134,17 @@ bool test_iterator_edge() {
complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j));
complex.remove_edge(Vertex_handle(2), Vertex_handle(3));
complex.remove_edge(Vertex_handle(3), Vertex_handle(5));
- std::cerr << "complex.num_edges():" << complex.num_edges() << std::endl;
+ std::cout << "complex.num_edges():" << complex.num_edges() << std::endl;
int num_edges_seen = 0;
for (auto edge : complex.edge_range()) {
- std::cerr << "edge :" << complex[edge] << std::endl;
+ std::cout << "edge :" << complex[edge] << std::endl;
++num_edges_seen;
}
- return num_edges_seen == n * (n - 1) / 2 - 2;
+ BOOST_CHECK(num_edges_seen == n * (n - 1) / 2 - 2);
}
-bool test_iterator_edge2() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_edge2) {
const int n = 10;
Complex complex(n);
for (int i = 0; i < n; i++)
@@ -166,33 +152,16 @@ bool test_iterator_edge2() {
complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j));
complex.remove_edge(Vertex_handle(2), Vertex_handle(3));
complex.remove_edge(Vertex_handle(3), Vertex_handle(5));
- std::cerr << "complex.num_edges():" << complex.num_edges() << std::endl;
+ std::cout << "complex.num_edges():" << complex.num_edges() << std::endl;
int num_neigbors_seen = 0;
for (auto neighbor : complex.vertex_range(Vertex_handle(2))) {
- std::cerr << "neighbor" << neighbor << std::endl;
+ std::cout << "neighbor" << neighbor << std::endl;
++num_neigbors_seen;
}
- return num_neigbors_seen == 8;
+ BOOST_CHECK(num_neigbors_seen == 8);
}
-bool test_iterator_edge3() {
- const int n = 10;
- Complex complex(n);
- for (int i = 0; i < n; i++)
- for (int j = 0; j < i; j++)
- complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j));
- complex.remove_edge(Vertex_handle(2), Vertex_handle(3));
- complex.remove_edge(Vertex_handle(3), Vertex_handle(5));
- std::cerr << "complex.num_edges():" << complex.num_edges() << std::endl;
- int num_neigbors_seen = 0;
- for (auto edge : complex.edge_range(Vertex_handle(2))) {
- std::cerr << edge << std::endl;
- ++num_neigbors_seen;
- }
- return num_neigbors_seen == 8;
-}
-
-bool test_iterator_triangles() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_triangles) {
const int n = 7;
Complex complex(n);
//create a "ring" around '0'
@@ -202,24 +171,20 @@ bool test_iterator_triangles() {
complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(i + 1));
complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(6));
- PRINT(complex.to_string());
+ std::cout << complex.to_string() << std::endl;
int num_triangles_seen = 0;
//for (auto t : complex.triangle_range(5)){
- TEST("triangles around 5 (should be 2 of them):");
for (auto t : complex.triangle_range(Vertex_handle(5))) {
- PRINT(t);
++num_triangles_seen;
}
- bool test = (num_triangles_seen == 2);
+ BOOST_CHECK(num_triangles_seen == 2);
num_triangles_seen = 0;
- TEST("triangles around 0 (should be 6 of them):");
for (auto t : complex.triangle_range(Vertex_handle(0))) {
- PRINT(t);
++num_triangles_seen;
}
- test = test && (num_triangles_seen == 6);
+ BOOST_CHECK(num_triangles_seen == 6);
// we now add another triangle
complex.add_vertex();
@@ -228,22 +193,14 @@ bool test_iterator_triangles() {
complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(6)));
num_triangles_seen = 0;
- TEST("triangles (should be 6 of them):");
num_triangles_seen = 0;
for (auto t : complex.triangle_range()) {
- PRINT(t);
++num_triangles_seen;
}
- test = test && (num_triangles_seen == 6);
- PRINT(num_triangles_seen);
-
- return test;
+ BOOST_CHECK(num_triangles_seen == 6);
}
-
-//#include "combinatorics/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h"
-
-bool test_iterator_simplices() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_simplices) {
Complex complex(6);
complex.add_edge_without_blockers(Vertex_handle(0), Vertex_handle(1));
complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(2));
@@ -258,8 +215,6 @@ bool test_iterator_simplices() {
complex.add_blocker(Simplex(Vertex_handle(2), Vertex_handle(3), Vertex_handle(4), Vertex_handle(5)));
- bool correct_number_simplices = true;
-
std::map<Vertex_handle, unsigned> expected_num_simplices;
expected_num_simplices[Vertex_handle(0)] = 4;
@@ -270,120 +225,108 @@ bool test_iterator_simplices() {
expected_num_simplices[Vertex_handle(5)] = 7;
for (auto pair : expected_num_simplices) {
+ std::cout << "found list: ";
unsigned num_simplices_around = 0;
for (const auto& simplex : complex.star_simplex_range(pair.first)) {
simplex.dimension();
- DBGVALUE(simplex);
+ std::cout << simplex << " - ";
++num_simplices_around;
}
- correct_number_simplices = correct_number_simplices && (num_simplices_around == pair.second);
+ BOOST_CHECK(num_simplices_around == pair.second);
- DBGMSG("current vertex:", pair.first);
- DBGMSG("expected_num_simplices:", pair.second);
- DBGMSG("found:", num_simplices_around);
+ std::cout << std::endl << "current vertex:" << pair.first << " - ";
+ std::cout << "expected_num_simplices:" << pair.second << " - ";
+ std::cout << "found:" << num_simplices_around << std::endl;
}
- return correct_number_simplices;
}
-bool test_iterator_simplices2() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_simplices2) {
Complex complex(2);
complex.add_edge_without_blockers(Vertex_handle(0), Vertex_handle(1));
- for (const auto& s : complex.triangle_range()) {
- s.dimension();
- return false; // there are no triangles
- }
-
- unsigned num_simplices = 0;
-
-
- DBGVALUE(complex.to_string());
-
- for (const auto& simplex : complex.star_simplex_range(Vertex_handle(0))) {
- simplex.dimension();
- DBGVALUE(simplex);
- }
-
+ // Check there is no triangle
+ BOOST_CHECK(std::distance(complex.triangle_range().begin(), complex.triangle_range().end()) == 0);
- for (const auto& simplex : complex.complex_simplex_range()) {
- DBGVALUE(simplex);
- simplex.dimension();
- ++num_simplices;
- }
- bool correct_number_simplices = (num_simplices == 3);
- return correct_number_simplices;
+ // Star(0) is [{0},{0,1}]
+ BOOST_CHECK(std::distance(complex.star_simplex_range(Vertex_handle(0)).begin(),
+ complex.star_simplex_range(Vertex_handle(0)).end()) == 2);
+
+ // No blocker
+ BOOST_CHECK(std::distance(complex.blocker_range(Vertex_handle(0)).begin(),
+ complex.blocker_range(Vertex_handle(0)).end()) == 0);
+
+ // Complex is [{0},{0,1},{1}]
+ BOOST_CHECK(std::distance(complex.complex_simplex_range().begin(),
+ complex.complex_simplex_range().end()) == 3);
}
-bool test_iterator_simplices3() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_simplices3) {
Complex complex(3);
complex.add_edge_without_blockers(Vertex_handle(0), Vertex_handle(1));
complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(2));
complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(0));
complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2)));
- unsigned num_simplices = 0;
-
- for (const auto& simplex : complex.star_simplex_range(Vertex_handle(0))) {
- simplex.dimension();
- DBGVALUE(simplex);
- }
+ // Check there is no triangle
+ BOOST_CHECK(std::distance(complex.triangle_range().begin(), complex.triangle_range().end()) == 0);
+ // Star(0) is [{0},{0,1},{0,2}]
+ BOOST_CHECK(std::distance(complex.star_simplex_range(Vertex_handle(0)).begin(),
+ complex.star_simplex_range(Vertex_handle(0)).end()) == 3);
- for (const auto& simplex : complex.complex_simplex_range()) {
- DBGVALUE(simplex);
- simplex.dimension();
- ++num_simplices;
- }
- bool correct_number_simplices = (num_simplices == 6);
- return correct_number_simplices;
+ // blocker(0) is [{0,1,2}]
+ BOOST_CHECK(std::distance(complex.blocker_range(Vertex_handle(0)).begin(),
+ complex.blocker_range(Vertex_handle(0)).end()) == 1);
+
+ // Complex is [{0},{0,1},{0,2},{1},{1,2},{2}]
+ BOOST_CHECK(std::distance(complex.complex_simplex_range().begin(),
+ complex.complex_simplex_range().end()) == 6);
}
-bool test_iterator_simplices4() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_simplices4) {
Complex empty_complex;
for (auto v : empty_complex.vertex_range()) {
- (void) v;
+ std::cout << v;
+ BOOST_CHECK(false);
}
for (auto e : empty_complex.edge_range()) {
- empty_complex[e];
+ std::cout << e;
+ BOOST_CHECK(false);
}
for (auto t : empty_complex.triangle_range()) {
- t.dimension();
+ std::cout << t;
+ BOOST_CHECK(false);
}
for (auto s : empty_complex.complex_simplex_range()) {
- s.dimension();
+ std::cout << s;
+ BOOST_CHECK(false);
}
- return true;
}
-bool test_iterator_coboundary() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_coboundary) {
Complex c;
build_complete(4, c);
c.remove_edge(Vertex_handle(1), Vertex_handle(3));
- PRINT(c.to_string());
+ std::cout << c.to_string();
Simplex s02(Vertex_handle(0), Vertex_handle(2));
int n = 0;
std::set<Simplex> expected;
expected.insert(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2)));
expected.insert(Simplex(Vertex_handle(0), Vertex_handle(2), Vertex_handle(3)));
for (const auto & s : c.coboundary_range(s02)) {
- PRINT(s);
- if (expected.find(s) == expected.end())
- return false;
+ BOOST_CHECK(expected.find(s) != expected.end());
++n;
}
- return n == 2;
+ BOOST_CHECK(n == 2);
}
-
-
-
template<typename Map>
auto blocker_range(Map map) -> decltype(map | boost::adaptors::map_values) {
return map | boost::adaptors::map_values;
}
-bool test_iterator_blockers() {
+BOOST_AUTO_TEST_CASE(test_skeleton_iterator_blockers) {
Complex complex;
Simplex alpha;
Simplex vertex_set_expected;
@@ -396,34 +339,36 @@ bool test_iterator_blockers() {
complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j));
}
- complex.add_blocker(Simplex(Vertex_handle(10), Vertex_handle(11), Vertex_handle(12)));
- complex.add_blocker(Simplex(Vertex_handle(2), Vertex_handle(1), Vertex_handle(10)));
- complex.add_blocker(Simplex(Vertex_handle(10), Vertex_handle(9), Vertex_handle(15)));
- complex.add_blocker(Simplex(Vertex_handle(1), Vertex_handle(9), Vertex_handle(8)));
+ std::vector<Simplex> myBlockers;
+ myBlockers.push_back(Simplex(Vertex_handle(10), Vertex_handle(11), Vertex_handle(12)));
+ myBlockers.push_back(Simplex(Vertex_handle(2), Vertex_handle(1), Vertex_handle(10)));
+ myBlockers.push_back(Simplex(Vertex_handle(10), Vertex_handle(9), Vertex_handle(15)));
+ myBlockers.push_back(Simplex(Vertex_handle(1), Vertex_handle(9), Vertex_handle(8)));
+
+ for (auto blocker : myBlockers)
+ complex.add_blocker(blocker);
- // Print result
int num_blockers = 0;
for (auto blockers : complex.blocker_range(Vertex_handle(10))) {
- TESTVALUE(*blockers);
+ // Only the first 3 blockers contain vertex 10
+ BOOST_CHECK(*blockers == myBlockers[num_blockers]);
num_blockers++;
}
- bool test = (num_blockers == 3);
+ BOOST_CHECK(num_blockers == 3);
num_blockers = 0;
for (auto blockers : complex.blocker_range()) {
- TESTVALUE(*blockers);
+ for (auto block_ptr = myBlockers.begin(); block_ptr < myBlockers.end(); block_ptr++)
+ if (*block_ptr == *blockers)
+ myBlockers.erase(block_ptr);
num_blockers++;
}
- test = test && (num_blockers == 4);
-
- return test;
+ BOOST_CHECK(num_blockers == 4);
+ BOOST_CHECK(myBlockers.empty());
}
-bool test_link0() {
-
- enum {
- a, b, c, d, n
- };
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_link0) {
+ enum { a, b, c, d, n };
Complex complex(n);
complex.add_edge_without_blockers(Vertex_handle(b), Vertex_handle(c));
complex.add_edge_without_blockers(Vertex_handle(c), Vertex_handle(d));
@@ -431,23 +376,19 @@ bool test_link0() {
Skeleton_blocker_link_complex L(complex, alpha);
auto L2 = complex.link(alpha);
- if (L != L2) return false;
-
- PRINT(L.num_vertices());
- PRINT(L.to_string());
+ BOOST_CHECK(L == L2);
- bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(b)));
- bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(d)));
- bool test3 = L.num_edges() == 0;
- bool test4 = L.num_blockers() == 0;
- return test1 && test2 && test3&&test4;
+ std::cout << L.to_string();
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(b))));
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(d))));
+ BOOST_CHECK(L.num_edges() == 0);
+ BOOST_CHECK(L.num_blockers() == 0);
}
-bool test_link1() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_link1) {
Complex complex;
-
// Build the complexes
for (int i = 0; i < 20; i++) {
complex.add_vertex();
@@ -461,26 +402,23 @@ bool test_link1() {
// Complexes built
auto L2 = complex.link(alpha);
- if (L != L2) return false;
+ BOOST_CHECK(L == L2);
// verification
- bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(10)));
- bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(11)));
- bool test3 = L.contains_vertex(*L.get_address(Root_vertex_handle(13)));
- bool test4 = L.num_edges() == 3;
- bool test5 = L.num_blockers() == 0;
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(10))));
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(11))));
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(13))));
+ BOOST_CHECK(L.num_edges() == 3);
+ BOOST_CHECK(L.num_blockers() == 0);
Root_simplex_handle simplex;
simplex.add_vertex(Root_vertex_handle(10));
simplex.add_vertex(Root_vertex_handle(11));
simplex.add_vertex(Root_vertex_handle(13));
- bool test6(L.get_simplex_address(simplex));
- bool test7 = L.contains(*(L.get_simplex_address(simplex)));
- std::cerr << "----> Ocomplex \n";
- return test1 && test2 && test3 && test4 && test5 && test6&&test7;
-
+ BOOST_CHECK(L.get_simplex_address(simplex));
+ BOOST_CHECK(L.contains(*(L.get_simplex_address(simplex))));
}
-bool test_link2() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_link2) {
Complex complex;
Simplex alpha;
@@ -499,30 +437,28 @@ bool test_link2() {
// Complexes built
// Print result
- std::cerr << "complex complex" << complex.to_string();
- std::cerr << std::endl << std::endl;
- std::cerr << "L= Link_complex(" << alpha << ") : \n" << L.to_string();
+ std::cout << "complex complex" << complex.to_string();
+ std::cout << std::endl << std::endl;
+ std::cout << "L= Link_complex(" << alpha << ") : \n" << L.to_string();
auto L2 = complex.link(alpha);
- if (L != L2) return false;
+ BOOST_CHECK(L == L2);
// verification
- bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(10)));
- bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(11)));
- bool test3 = L.contains_vertex(*L.get_address(Root_vertex_handle(13)));
- bool test4 = L.num_edges() == 3;
- bool test5 = L.num_blockers() == 1;
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(10))));
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(11))));
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(13))));
+ BOOST_CHECK(L.num_edges() == 3);
+ BOOST_CHECK(L.num_blockers() == 1);
Root_simplex_handle simplex;
simplex.add_vertex(Root_vertex_handle(10));
simplex.add_vertex(Root_vertex_handle(11));
simplex.add_vertex(Root_vertex_handle(13));
- bool test6 = L.contains_blocker(*(L.get_simplex_address(simplex)));
- std::cerr << "----> Ocomplex \n";
- return test1 && test2 && test3 && test4 && test5&&test6;
+ BOOST_CHECK(L.contains_blocker(*(L.get_simplex_address(simplex))));
}
-bool test_link3() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_link3) {
Complex complex;
Simplex alpha;
@@ -541,26 +477,24 @@ bool test_link3() {
// Complexes built
// Print result
- std::cerr << "complex complex" << complex.to_string();
- std::cerr << std::endl << std::endl;
- std::cerr << "L= Link_complex(" << alpha << ") : \n" << L.to_string();
+ std::cout << "complex complex" << complex.to_string();
+ std::cout << std::endl << std::endl;
+ std::cout << "L= Link_complex(" << alpha << ") : \n" << L.to_string();
auto L2 = complex.link(alpha);
- if (L != L2) return false;
-
+ BOOST_CHECK(L == L2);
// verification
- bool test = assert_vertex(L, *L.get_address(Root_vertex_handle(10)));
- test = test && assert_vertex(L, *L.get_address(Root_vertex_handle(11)));
- test = test && assert_vertex(L, *L.get_address(Root_vertex_handle(13)));
- test = test && L.num_edges() == 2;
- test = test && L.contains_edge(*L.get_address(Root_vertex_handle(10)), *L.get_address(Root_vertex_handle(13)));
- test = test && L.contains_edge(*L.get_address(Root_vertex_handle(13)), *L.get_address(Root_vertex_handle(11)));
- test = test && L.num_blockers() == 0;
- return test;
+ BOOST_CHECK(L.contains(static_cast<Simplex> (*L.get_address(Root_vertex_handle(10)))));
+ BOOST_CHECK(L.contains(static_cast<Simplex> (*L.get_address(Root_vertex_handle(11)))));
+ BOOST_CHECK(L.contains(static_cast<Simplex> (*L.get_address(Root_vertex_handle(13)))));
+ BOOST_CHECK(L.num_edges() == 2);
+ BOOST_CHECK(L.contains_edge(*L.get_address(Root_vertex_handle(10)), *L.get_address(Root_vertex_handle(13))));
+ BOOST_CHECK(L.contains_edge(*L.get_address(Root_vertex_handle(13)), *L.get_address(Root_vertex_handle(11))));
+ BOOST_CHECK(L.num_blockers() == 0);
}
-bool test_link4() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_link4) {
Complex complex;
// Build the complexes
@@ -577,42 +511,37 @@ bool test_link4() {
// Complexes built
// verification
- bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(10)));
- bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(11)));
- bool test3 = L.contains_vertex(*L.get_address(Root_vertex_handle(13)));
- bool test4 = L.num_edges() == 3;
- bool test5 = L.num_blockers() == 1;
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(10))));
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(11))));
+ BOOST_CHECK(L.contains_vertex(*L.get_address(Root_vertex_handle(13))));
+ BOOST_CHECK(L.num_edges() == 3);
+ BOOST_CHECK(L.num_blockers() == 1);
Root_simplex_handle simplex;
simplex.add_vertex(Root_vertex_handle(10));
simplex.add_vertex(Root_vertex_handle(11));
simplex.add_vertex(Root_vertex_handle(13));
- bool test6 = L.contains_blocker(*(L.get_simplex_address(simplex)));
- std::cerr << "----> Ocomplex \n";
- return test1 && test2 && test3 && test4 && test5&&test6;
-
+ BOOST_CHECK(L.contains_blocker(*(L.get_simplex_address(simplex))));
}
-bool test_link5() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_link5) {
Complex complex(0);
// Build the complexes
build_complete(4, complex);
complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)));
Simplex alpha(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2));
-
-
- Skeleton_blocker_link_complex L(complex, alpha); // Complexes built
+ Skeleton_blocker_link_complex L(complex, alpha);
+ // Complexes built
// Print result
- PRINT(complex.to_string());
- std::cerr << std::endl << std::endl;
- PRINT(L.to_string());
+ std::cout << "Complex: " << complex.to_string()<< std::endl << std::endl;
+ std::cout << "Link: " << L.to_string() << std::endl;
// verification
- return L.num_vertices() == 0;
+ BOOST_CHECK(L.num_vertices() == 0);
}
-bool test_link6() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_link6) {
Complex complex(0);
// Build the complexes
build_complete(4, complex);
@@ -625,15 +554,14 @@ bool test_link6() {
build_link_of_blocker(complex, alpha, link_blocker_alpha);
// Print result
- PRINT(complex.to_string());
- std::cerr << std::endl << std::endl;
- PRINT(link_blocker_alpha.to_string());
+ std::cout << "Complex: " << complex.to_string()<< std::endl << std::endl;
+ std::cout << "Link: " << link_blocker_alpha.to_string() << std::endl;
// verification
- return link_blocker_alpha.num_vertices() == 1;
+ BOOST_CHECK(link_blocker_alpha.num_vertices() == 1);
}
-bool test_link7() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_link7) {
Complex complex(0);
// Build the complexes
build_complete(6, complex);
@@ -656,27 +584,22 @@ bool test_link7() {
//the result should be the edge {6,7} plus the blocker {0,1,2}
// Print result
- PRINT(complex.to_string());
- std::cerr << std::endl << std::endl;
- DBGVALUE(link_blocker_alpha.to_string());
+ std::cout << "Complex: " << complex.to_string()<< std::endl << std::endl;
+ std::cout << "Link: " << link_blocker_alpha.to_string() << std::endl;
Skeleton_blocker_link_complex link_blocker_alpha_cpy = link_blocker_alpha;
- DBGVALUE(link_blocker_alpha_cpy.to_string());
-
- bool equal_complexes =
- (link_blocker_alpha.num_vertices() == link_blocker_alpha_cpy.num_vertices())
- &&(link_blocker_alpha.num_blockers() == link_blocker_alpha_cpy.num_blockers())
- &&(link_blocker_alpha.num_edges() == link_blocker_alpha_cpy.num_edges())
- ;
- DBGVALUE((link_blocker_alpha.num_blockers() == link_blocker_alpha_cpy.num_blockers()));
- DBGVALUE((link_blocker_alpha.num_blockers()));
- DBGVALUE((link_blocker_alpha_cpy.num_blockers()));
+ std::cout << "Link copy: " << link_blocker_alpha_cpy.to_string() << std::endl;
- DBGVALUE(equal_complexes);
+ BOOST_CHECK(link_blocker_alpha.num_vertices() == link_blocker_alpha_cpy.num_vertices());
+ BOOST_CHECK(link_blocker_alpha.num_blockers() == link_blocker_alpha_cpy.num_blockers());
+ BOOST_CHECK(link_blocker_alpha.num_edges() == link_blocker_alpha_cpy.num_edges());
+ BOOST_CHECK((link_blocker_alpha.num_blockers() == link_blocker_alpha_cpy.num_blockers()));
// verification
- return link_blocker_alpha.num_vertices() == 5 && link_blocker_alpha.num_edges() == 4 && link_blocker_alpha.num_blockers() == 1 && equal_complexes;
+ BOOST_CHECK(link_blocker_alpha.num_vertices() == 5);
+ BOOST_CHECK(link_blocker_alpha.num_edges() == 4);
+ BOOST_CHECK(link_blocker_alpha.num_blockers() == 1);
}
template<typename SimplexHandle>
@@ -696,7 +619,7 @@ void add_triangle(int a, int b, int c, std::list<SimplexHandle>& simplices) {
simplices.push_back(Simplex(Vertex_handle(a), Vertex_handle(b), Vertex_handle(c)));
}
-bool test_constructor() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_constructor) {
std::list <Simplex> simplices;
simplices.push_back(Simplex(Vertex_handle(0)));
@@ -714,7 +637,6 @@ bool test_constructor() {
add_triangle_edges(1, 3, 4, simplices);
add_triangle_edges(1, 2, 4, simplices);
-
add_triangle(0, 1, 5, simplices);
add_triangle(1, 2, 3, simplices);
add_triangle(1, 3, 4, simplices);
@@ -723,9 +645,11 @@ bool test_constructor() {
Complex complex(simplices.begin(), simplices.end());
- PRINT(complex.to_string());
+ std::cout << "Constructor 1:\n" << complex.to_string();
- return ( complex.num_vertices() == 6 && complex.num_edges() == 10 && complex.num_blockers() == 2);
+ BOOST_CHECK(complex.num_vertices() == 6);
+ BOOST_CHECK(complex.num_edges() == 10);
+ BOOST_CHECK(complex.num_blockers() == 2);
}
std::list<Simplex> subfaces(Simplex top_face) {
@@ -748,7 +672,7 @@ std::list<Simplex> subfaces(Simplex top_face) {
}
}
-bool test_constructor2() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_constructor2) {
Simplex simplex;
for (int i = 0; i < 5; ++i)
simplex.add_vertex(static_cast<Vertex_handle> (i));
@@ -758,37 +682,40 @@ bool test_constructor2() {
Complex complex(simplices.begin(), simplices.end());
- PRINT(complex.to_string());
+ std::cout << "Constructor 2:\n" << complex.to_string();
for (auto b : complex.const_blocker_range()) {
std::cout << "b:" << b << std::endl;
}
- return ( complex.num_vertices() == 5 && complex.num_edges() == 10 && complex.num_blockers() == 1);
+ BOOST_CHECK(complex.num_vertices() == 5);
+ BOOST_CHECK(complex.num_edges() == 10);
+ BOOST_CHECK(complex.num_blockers() == 1);
}
-bool test_constructor3() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_constructor3) {
typedef Vertex_handle Vh;
typedef Simplex Sh;
std::vector<Simplex> simplices;
auto subf(subfaces(Sh(Vh(0), Vh(1), Vh(2))));
subf.pop_back(); //remove max face -> now a blocker 012
simplices.insert(simplices.begin(), subf.begin(), subf.end());
- DBGCONT(simplices);
+
Complex complex(simplices.begin(), simplices.end());
- DBGVALUE(complex.to_string());
+ std::cout << "Constructor 3:\n" << complex.to_string();
- if (complex.num_blockers() != 1) return false;
+ BOOST_CHECK(complex.num_blockers() == 1);
Sh expected_blocker(Vh(0), Vh(1), Vh(2));
for (auto b : complex.const_blocker_range())
- if (*b != expected_blocker) return false;
+ BOOST_CHECK(*b == expected_blocker);
- return complex.num_vertices() == 3 && complex.num_blockers() == 1;
+ BOOST_CHECK(complex.num_vertices() == 3);
+ BOOST_CHECK(complex.num_blockers() == 1);
}
-bool test_constructor4() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_constructor4) {
typedef Vertex_handle Vh;
typedef Simplex Sh;
std::vector<Simplex> simplices;
@@ -799,19 +726,20 @@ bool test_constructor4() {
simplices.push_back(Sh(Vh(4), Vh(1)));
simplices.push_back(Sh(Vh(4), Vh(0)));
- DBGCONT(simplices);
Complex complex(simplices.begin(), simplices.end());
- DBGVALUE(complex.to_string());
- if (complex.num_blockers() != 1) return false;
+ std::cout << "Constructor 4:\n" << complex.to_string();
+ BOOST_CHECK(complex.num_blockers() == 1);
Sh expected_blocker(Vh(0), Vh(1), Vh(4));
for (auto b : complex.const_blocker_range())
- if (*b != expected_blocker) return false;
+ BOOST_CHECK(*b == expected_blocker);
- return complex.num_vertices() == 5 && complex.num_blockers() == 1 && complex.num_edges() == 8;
+ BOOST_CHECK(complex.num_vertices() == 5);
+ BOOST_CHECK(complex.num_blockers() == 1);
+ BOOST_CHECK(complex.num_edges() == 8);
}
-bool test_constructor5() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_constructor5) {
typedef Vertex_handle Vh;
typedef Simplex Sh;
std::vector<Simplex> simplices;
@@ -828,15 +756,16 @@ bool test_constructor5() {
simplices.push_back(Sh(Vh(5), Vh(2)));
simplices.push_back(Sh(Vh(5), Vh(0)));
- DBGCONT(simplices);
Complex complex(simplices.begin(), simplices.end());
- DBGVALUE(complex.to_string());
+ std::cout << "Constructor 5:\n" << complex.to_string();
- return complex.num_vertices() == 6 && complex.num_blockers() == 3 && complex.num_edges() == 9;
+ BOOST_CHECK(complex.num_vertices() == 6);
+ BOOST_CHECK(complex.num_blockers() == 3);
+ BOOST_CHECK(complex.num_edges() == 9);
}
-bool test_constructor6() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_constructor6) {
typedef Vertex_handle Vh;
typedef Simplex Sh;
std::vector<Simplex> simplices;
@@ -847,19 +776,19 @@ bool test_constructor6() {
if (s != s1 && s != s2) simplices.push_back(s);
}
- DBGCONT(simplices);
Complex complex(simplices.begin(), simplices.end());
- DBGVALUE(complex.to_string());
+ std::cout << "Constructor 6:\n" << complex.to_string();
- if (complex.num_blockers() != 1) return false;
+ BOOST_CHECK(complex.num_vertices() == 4);
+ BOOST_CHECK(complex.num_blockers() == 1);
+ BOOST_CHECK(complex.num_edges() == 6);
Sh expected_blocker(Vh(1), Vh(2), Vh(3));
for (auto b : complex.const_blocker_range())
- if (*b != expected_blocker) return false;
- return complex.num_vertices() == 4 && complex.num_blockers() == 1 && complex.num_edges() == 6;
+ BOOST_CHECK(*b == expected_blocker);
}
-bool test_constructor7() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_constructor7) {
typedef Vertex_handle Vh;
typedef Simplex Sh;
std::vector<Simplex> simplices;
@@ -871,16 +800,17 @@ bool test_constructor7() {
//get complex from top faces
Complex complex(Gudhi::skeleton_blocker::make_complex_from_top_faces<Complex>(simplices.begin(), simplices.end()));
- DBGVALUE(complex.to_string());
+ std::cout << "Constructor 7:\n" << complex.to_string();
- if (complex.num_blockers() != 1) return false;
+ BOOST_CHECK(complex.num_vertices() == 4);
+ BOOST_CHECK(complex.num_blockers() == 1);
+ BOOST_CHECK(complex.num_edges() == 6);
Sh expected_blocker(Vh(0), Vh(1), Vh(2), Vh(3));
for (auto b : complex.const_blocker_range())
- if (*b != expected_blocker) return false;
- return complex.num_vertices() == 4 && complex.num_blockers() == 1 && complex.num_edges() == 6;
+ BOOST_CHECK(*b == expected_blocker);
}
-bool test_constructor8() {
+BOOST_AUTO_TEST_CASE(test_skeleton_blocker_complex_constructor8) {
typedef Vertex_handle Vh;
typedef Simplex Sh;
std::vector<Simplex> simplices;
@@ -893,49 +823,9 @@ bool test_constructor8() {
//get complex from top faces
Complex complex(Gudhi::skeleton_blocker::make_complex_from_top_faces<Complex>(simplices.begin(), simplices.end()));
- DBGVALUE(complex.to_string());
-
- return complex.num_vertices() == 4 && complex.num_blockers() == 2 && complex.num_edges() == 5;
-}
-
-int main(int argc, char *argv[]) {
- Tests tests_complex;
- tests_complex.add("test simplex", test_simplex);
- tests_complex.add("test_num_simplices", test_num_simplices);
- tests_complex.add("test_link0", test_link0);
- tests_complex.add("test_link1", test_link1);
- tests_complex.add("test_link2", test_link2);
- tests_complex.add("test_link3", test_link3);
- tests_complex.add("test_link4", test_link4);
- tests_complex.add("test_link5", test_link5);
- tests_complex.add("test_link6", test_link6);
- tests_complex.add("test_link7", test_link7);
-
- tests_complex.add("test_constructor_list_simplices", test_constructor);
- tests_complex.add("test_constructor_list_simplices2", test_constructor2);
- tests_complex.add("test_constructor_list_simplices3", test_constructor3);
- tests_complex.add("test_constructor_list_simplices4", test_constructor4);
- tests_complex.add("test_constructor_list_simplices5", test_constructor5);
- tests_complex.add("test_constructor_list_simplices6", test_constructor6);
- tests_complex.add("test_constructor_list_simplices7", test_constructor7);
- tests_complex.add("test_constructor_list_simplices8", test_constructor8);
-
- tests_complex.add("test iterator vertices 1", test_iterator_vertices1);
- tests_complex.add("test iterator vertices 2", test_iterator_vertices2);
- tests_complex.add("test iterator edges", test_iterator_edge);
- tests_complex.add("test iterator edges 2", test_iterator_edge2);
- tests_complex.add("test iterator edges 3", test_iterator_edge3);
- tests_complex.add("test iterator blockers", test_iterator_blockers);
- tests_complex.add("test_iterator_triangles", test_iterator_triangles);
- tests_complex.add("test iterator simplices", test_iterator_simplices);
- tests_complex.add("test iterator simplices2", test_iterator_simplices2);
- tests_complex.add("test iterator simplices3", test_iterator_simplices3);
- tests_complex.add("test iterator simplices4", test_iterator_simplices4);
- tests_complex.add("test iterator coboundary", test_iterator_coboundary);
-
- if (tests_complex.run()) {
- return EXIT_SUCCESS;
- } else {
- return EXIT_FAILURE;
- }
+ std::cout << "Constructor 8:\n" << complex.to_string();
+
+ BOOST_CHECK(complex.num_vertices() == 4);
+ BOOST_CHECK(complex.num_blockers() == 2);
+ BOOST_CHECK(complex.num_edges() == 5);
}