summaryrefslogtreecommitdiff
path: root/src/Coxeter_triangulation/test/function_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Coxeter_triangulation/test/function_test.cpp')
-rw-r--r--src/Coxeter_triangulation/test/function_test.cpp43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/Coxeter_triangulation/test/function_test.cpp b/src/Coxeter_triangulation/test/function_test.cpp
index c9c3f55b..d3c8d46c 100644
--- a/src/Coxeter_triangulation/test/function_test.cpp
+++ b/src/Coxeter_triangulation/test/function_test.cpp
@@ -11,7 +11,7 @@
// workaround for the annoying boost message in boost 1.69
#define BOOST_PENDING_INTEGER_LOG2_HPP
#include <boost/integer/integer_log2.hpp>
-// end workaround
+// end workaround
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "function"
@@ -48,18 +48,17 @@ template <class Function>
void test_function(const Function& fun) {
Eigen::VectorXd seed = fun.seed();
Eigen::VectorXd res_seed = fun(fun.seed());
- BOOST_CHECK( seed.size() == (long int)fun.amb_d() );
- BOOST_CHECK( res_seed.size() == (long int)fun.cod_d() );
- for (std::size_t i = 0; i < fun.cod_d(); i++)
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(res_seed(i), 0., 1e-10);
+ BOOST_CHECK(seed.size() == (long int)fun.amb_d());
+ BOOST_CHECK(res_seed.size() == (long int)fun.cod_d());
+ for (std::size_t i = 0; i < fun.cod_d(); i++) GUDHI_TEST_FLOAT_EQUALITY_CHECK(res_seed(i), 0., 1e-10);
}
BOOST_AUTO_TEST_CASE(function) {
-
{
// the sphere testing part
std::size_t m = 3, d = 5;
- Eigen::VectorXd center(d); center << 2, 1.5, -0.5, 4.5, -1;
+ Eigen::VectorXd center(d);
+ center << 2, 1.5, -0.5, 4.5, -1;
double radius = 5;
typedef Function_Sm_in_Rd Function_sphere;
Function_sphere fun_sphere(radius, m, d, center);
@@ -68,9 +67,8 @@ BOOST_AUTO_TEST_CASE(function) {
{
// the affine plane testing part
std::size_t m = 0, d = 5;
- Eigen::MatrixXd normal_matrix = Eigen::MatrixXd::Zero(d, d-m);
- for (std::size_t i = 0; i < d-m; ++i)
- normal_matrix(i,i) = 1;
+ Eigen::MatrixXd normal_matrix = Eigen::MatrixXd::Zero(d, d - m);
+ for (std::size_t i = 0; i < d - m; ++i) normal_matrix(i, i) = 1;
typedef Function_affine_plane_in_Rd Function_plane;
Function_plane fun_plane(normal_matrix);
test_function(fun_plane);
@@ -81,8 +79,7 @@ BOOST_AUTO_TEST_CASE(function) {
auto x = Eigen::VectorXd::Constant(k, 1);
Constant_function fun_const(d, k, x);
Eigen::VectorXd res_zero = fun_const(Eigen::VectorXd::Zero(d));
- for (std::size_t i = 0; i < k; ++i)
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(res_zero(i), x(i), 1e-10);
+ for (std::size_t i = 0; i < k; ++i) GUDHI_TEST_FLOAT_EQUALITY_CHECK(res_zero(i), x(i), 1e-10);
}
{
// the chair function
@@ -119,10 +116,10 @@ BOOST_AUTO_TEST_CASE(function) {
Eigen::MatrixXd id_matrix = matrix.transpose() * matrix;
for (std::size_t i = 0; i < 5; ++i)
for (std::size_t j = 0; j < 5; ++j)
- if (i == j)
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(id_matrix(i,j), 1.0, 1e-10);
- else
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(id_matrix(i,j), 0.0, 1e-10);
+ if (i == j)
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(id_matrix(i, j), 1.0, 1e-10);
+ else
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(id_matrix(i, j), 0.0, 1e-10);
}
{
// function embedding
@@ -137,7 +134,7 @@ BOOST_AUTO_TEST_CASE(function) {
// function linear transformation
Eigen::MatrixXd matrix = Eigen::MatrixXd::Random(5, 5);
- BOOST_CHECK( matrix.determinant() != 0. );
+ BOOST_CHECK(matrix.determinant() != 0.);
auto fun_lin = make_linear_transformation(fun_trans, matrix);
test_function(fun_lin);
@@ -150,7 +147,7 @@ BOOST_AUTO_TEST_CASE(function) {
Function_sphere fun_sphere(1, 1);
auto fun_prod = make_product_function(fun_sphere, fun_sphere, fun_sphere);
test_function(fun_prod);
-
+
// function PL approximation
Coxeter_triangulation<> cox_tr(6);
typedef Coxeter_triangulation<>::Vertex_handle Vertex_handle;
@@ -159,17 +156,15 @@ BOOST_AUTO_TEST_CASE(function) {
Eigen::VectorXd x0 = cox_tr.cartesian_coordinates(v0);
Eigen::VectorXd value0 = fun_prod(x0);
Eigen::VectorXd pl_value0 = fun_pl(x0);
- for (std::size_t i = 0; i < fun_pl.cod_d(); i++)
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(value0(i), pl_value0(i), 1e-10);
+ for (std::size_t i = 0; i < fun_pl.cod_d(); i++) GUDHI_TEST_FLOAT_EQUALITY_CHECK(value0(i), pl_value0(i), 1e-10);
Vertex_handle v1 = v0;
v1[0] += 1;
Eigen::VectorXd x1 = cox_tr.cartesian_coordinates(v1);
Eigen::VectorXd value1 = fun_prod(x1);
Eigen::VectorXd pl_value1 = fun_pl(x1);
+ for (std::size_t i = 0; i < fun_pl.cod_d(); i++) GUDHI_TEST_FLOAT_EQUALITY_CHECK(value1(i), pl_value1(i), 1e-10);
+ Eigen::VectorXd pl_value_mid = fun_pl(0.5 * x0 + 0.5 * x1);
for (std::size_t i = 0; i < fun_pl.cod_d(); i++)
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(value1(i), pl_value1(i), 1e-10);
- Eigen::VectorXd pl_value_mid = fun_pl(0.5*x0 + 0.5*x1);
- for (std::size_t i = 0; i < fun_pl.cod_d(); i++)
- GUDHI_TEST_FLOAT_EQUALITY_CHECK(0.5*value0(i) + 0.5*value1(i), pl_value_mid(i), 1e-10);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(0.5 * value0(i) + 0.5 * value1(i), pl_value_mid(i), 1e-10);
}
}