34 #ifndef OPEN_WALKER_CORE_GTEST_UTILITIES_H 35 #define OPEN_WALKER_CORE_GTEST_UTILITIES_H 37 #include <gtest/gtest.h> 38 #include <Eigen/Dense> 39 #include <geometry_msgs/Quaternion.h> 40 #include <geometry_msgs/Point.h> 41 #include <geometry_msgs/Vector3.h> 42 #include <tf/LinearMath/Matrix3x3.h> 43 #include <tf/LinearMath/Quaternion.h> 49 const double PRECISION = 1e-7;
52 template <
typename _DerivedA,
typename _DerivedB>
53 ::testing::AssertionResult eigenMatrixNear(
const Eigen::MatrixBase<_DerivedA>& m1,
const std::string m1_name,
54 const Eigen::MatrixBase<_DerivedB>& m2,
const std::string m2_name,
55 double prec = PRECISION)
57 if(m1.cols() != m2.cols())
59 return ::testing::AssertionFailure()
60 <<
"Differnt number of cols for " << m1_name <<
" and " << m2_name <<
":\n" 61 << m1_name <<
".cols()" << m1.cols() <<
".\n" 62 << m2_name <<
".cols()" << m2.cols() <<
".\n";
64 if(m2.rows()!= m2.rows())
66 return ::testing::AssertionFailure()
67 <<
"Differnt number of rows for " << m1_name <<
" and " << m2_name <<
":\n" 68 << m1_name <<
".rows()" << m1.rows() <<
".\n" 69 << m2_name <<
".rows()" << m2.rows() <<
".\n";
71 if(m1.isApprox(m2,prec))
72 return ::testing::AssertionSuccess();
75 ::testing::AssertionResult res(
false);
76 res <<
"Detla between Eigen::Matrix " << m1_name <<
" and Eigen::Matrix " << m2_name <<
" detected:\n";
78 for (
int j = 0; j < m1.cols(); ++j)
80 for (
int i = 0; i < m1.rows(); ++i)
82 double delta = std::abs(m1(i,j) - m2(i,j));
84 res <<
"Detla at entry (" << i <<
"," << j <<
"):" <<
"\n";
85 res << m1_name <<
"(" << i <<
"," << j <<
")=" << m1(i,j) <<
".\n";
86 res << m2_name <<
"(" << i <<
"," << j <<
")=" << m2(i,j) <<
".\n";
87 res <<
"delta=" << delta <<
", prec=" << prec <<
".\n";
93 return ::testing::AssertionFailure();
98 template <
typename _DerivedA,
typename _DerivedB>
99 ::testing::AssertionResult eigenQuaternionNear(
const Eigen::QuaternionBase<_DerivedA>& Q_a,
const std::string q_a_name,
100 const Eigen::QuaternionBase<_DerivedB>& Q_b,
const std::string q_b_name,
101 double prec = PRECISION)
103 typedef typename Eigen::QuaternionBase<_DerivedA>::Matrix3 Matrix3A;
104 typedef typename Eigen::QuaternionBase<_DerivedB>::Matrix3 Matrix3B;
106 Matrix3A R_a = Q_a.toRotationMatrix();
107 Matrix3B R_b = Q_b.toRotationMatrix();
109 ::testing::AssertionResult res = eigenMatrixNear(R_a, q_a_name, R_b, q_b_name);
112 ::testing::AssertionResult res_wrapped(
false);
113 res_wrapped <<
"Detla between Eigen::Quaternion " << q_a_name <<
" and Eigen::Quaternion " << q_b_name <<
" detected:\n";
114 res_wrapped << res.message();
122 #endif // OPEN_WALKER_CORE_GTEST_UTILITIES_H Definition: gtest_utilities.h:45