Commit 6d7e07e0 authored by Justin Carpentier's avatar Justin Carpentier

spatial/force: improve coverage

parent 70d2af56
// //
// Copyright (c) 2017-2018 CNRS INRIA // Copyright (c) 2017-2019 CNRS INRIA
// //
#ifndef __pinocchio_force_ref_hpp__ #ifndef __pinocchio_force_ref_hpp__
...@@ -56,6 +56,8 @@ namespace pinocchio ...@@ -56,6 +56,8 @@ namespace pinocchio
FORCE_TYPEDEF_TPL(ForceRef); FORCE_TYPEDEF_TPL(ForceRef);
using Base::operator=; using Base::operator=;
using Base::operator==;
using Base::operator!=;
ForceRef(typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) f_like) ForceRef(typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) f_like)
: m_ref(f_like) : m_ref(f_like)
......
// //
// Copyright (c) 2015-2018 CNRS // Copyright (c) 2015-2019 CNRS INRIA
// Copyright (c) 2015-2016 Wandercraft, 86 rue de Paris 91400 Orsay, France. // Copyright (c) 2015-2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
// //
...@@ -41,6 +41,7 @@ namespace pinocchio ...@@ -41,6 +41,7 @@ namespace pinocchio
enum { Options = _Options }; enum { Options = _Options };
using Base::operator=; using Base::operator=;
using Base::operator!=;
using Base::linear; using Base::linear;
using Base::angular; using Base::angular;
......
...@@ -295,6 +295,11 @@ BOOST_AUTO_TEST_CASE ( test_Force ) ...@@ -295,6 +295,11 @@ BOOST_AUTO_TEST_CASE ( test_Force )
Vector6 bf_vec = bf; Vector6 bf_vec = bf;
Vector6 bf2_vec = bf2; Vector6 bf2_vec = bf2;
// std::stringstream
std::stringstream ss;
ss << bf << std::endl;
BOOST_CHECK(!ss.str().empty());
// Test .+. // Test .+.
Vector6 bfPbf2_vec = bf+bf2; Vector6 bfPbf2_vec = bf+bf2;
BOOST_CHECK(bfPbf2_vec.isApprox(bf_vec+bf2_vec, 1e-12)); BOOST_CHECK(bfPbf2_vec.isApprox(bf_vec+bf2_vec, 1e-12));
...@@ -315,7 +320,6 @@ BOOST_AUTO_TEST_CASE ( test_Force ) ...@@ -315,7 +320,6 @@ BOOST_AUTO_TEST_CASE ( test_Force )
Force bf4(bf2_vec); Force bf4(bf2_vec);
BOOST_CHECK(bf4.toVector().isApprox(bf2_vec, 1e-12)); BOOST_CHECK(bf4.toVector().isApprox(bf2_vec, 1e-12));
// Test action // Test action
ActionMatrixType aXb = amb; ActionMatrixType aXb = amb;
BOOST_CHECK(amb.act(bf).toVector().isApprox(aXb.inverse().transpose()*bf_vec, 1e-12)); BOOST_CHECK(amb.act(bf).toVector().isApprox(aXb.inverse().transpose()*bf_vec, 1e-12));
...@@ -334,9 +338,16 @@ BOOST_AUTO_TEST_CASE ( test_Force ) ...@@ -334,9 +338,16 @@ BOOST_AUTO_TEST_CASE ( test_Force )
// ensure that (vxv.toVector().isMuchSmallerThan(bf.toVector())); // ensure that (vxv.toVector().isMuchSmallerThan(bf.toVector()));
// Test isApprox // Test isApprox
const double eps = 1e-6;
BOOST_CHECK(bf == bf);
bf.setRandom();
bf2.setZero();
BOOST_CHECK(bf == bf); BOOST_CHECK(bf == bf);
BOOST_CHECK(bf != bf2);
BOOST_CHECK(bf.isApprox(bf)); BOOST_CHECK(bf.isApprox(bf));
BOOST_CHECK(!bf.isApprox(bf2));
const double eps = 1e-6;
Force bf_approx(bf); Force bf_approx(bf);
bf_approx.linear()[0] += eps/2.; bf_approx.linear()[0] += eps/2.;
BOOST_CHECK(bf_approx.isApprox(bf,eps)); BOOST_CHECK(bf_approx.isApprox(bf,eps));
...@@ -357,6 +368,14 @@ BOOST_AUTO_TEST_CASE ( test_Force ) ...@@ -357,6 +368,14 @@ BOOST_AUTO_TEST_CASE ( test_Force )
Forcef a_float = a.cast<float>(); Forcef a_float = a.cast<float>();
BOOST_CHECK(a_float.isApprox(a.cast<float>())); BOOST_CHECK(a_float.isApprox(a.cast<float>()));
} }
// Test scalar multiplication
const double alpha = 1.5;
Force b(Force::Random());
Force alpha_f = alpha * b;
Force f_alpha = b * alpha;
BOOST_CHECK(alpha_f == f_alpha);
} }
BOOST_AUTO_TEST_CASE (test_force_ref) BOOST_AUTO_TEST_CASE (test_force_ref)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment