GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: unittest/quaternion.cpp Lines: 27 27 100.0 %
Date: 2024-01-23 21:41:47 Branches: 162 318 50.9 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2019-2020 INRIA CNRS
3
//
4
5
#include <pinocchio/math/quaternion.hpp>
6
#include <pinocchio/spatial/se3.hpp>
7
8
#include <boost/variant.hpp> // to avoid C99 warnings
9
10
#include <boost/test/unit_test.hpp>
11
#include <boost/utility/binary.hpp>
12
13
BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
14
15
















4
BOOST_AUTO_TEST_CASE(test_assignQuaternion)
16
{
17
  using namespace pinocchio;
18
2
  const int max_tests = 1e5;
19
200002
  for(int k = 0; k < max_tests; ++k)
20
  {
21
200000
    const SE3 M(SE3::Random());
22

200000
    SE3::Quaternion quat_ref(M.rotation());
23
24
200000
    SE3::Quaternion quat;
25

200000
    quaternion::assignQuaternion(quat,M.rotation());
26
27



200000
    BOOST_CHECK(quat.coeffs().isApprox(quat_ref.coeffs()));
28
  }
29
2
}
30
31
















4
BOOST_AUTO_TEST_CASE(test_uniformRandom)
32
{
33
2
  srand(0);
34
35
  using namespace pinocchio;
36
2
  Eigen::Quaternion<double> q;
37
38
2050
  for (int i = 0; i < (1 << 10); ++i) {
39
2048
    quaternion::uniformRandom(q);
40







2048
    BOOST_CHECK_MESSAGE((q.coeffs().array().abs() <= 1).all(),
41
        "Quaternion coeffs out of bounds: " << i << ' ' << q.coeffs().transpose());
42
  }
43
2
}
44
45
















4
BOOST_AUTO_TEST_CASE(test_isNormalized)
46
{
47
2
  srand(0);
48
49
  using namespace pinocchio;
50
  typedef Eigen::Quaternion<double> Quaternion;
51
  typedef Quaternion::Coefficients Vector4;
52
53
#ifdef NDEBUG
54
  const int max_test = 1e6;
55
#else
56
2
  const int max_test = 1e2;
57
#endif
58
202
  for(int i = 0; i < max_test; ++i)
59
  {
60
200
    Quaternion q;
61


200
    q.coeffs() = Vector4::Random() + Vector4::Constant(2);
62



200
    BOOST_CHECK(!quaternion::isNormalized(q));
63
64
200
    q.normalize();
65



200
    BOOST_CHECK(quaternion::isNormalized(q));
66
  }
67
68
  // Specific check for the Zero vector
69




2
  BOOST_CHECK(!quaternion::isNormalized(Quaternion(Vector4::Zero())));
70
2
}
71
72
BOOST_AUTO_TEST_SUITE_END()
73