25 #ifndef INCLUDED_EigenTestHelpers_h_GUID_9C8A67BA_D846_4F94_8020_885E858600E3 26 #define INCLUDED_EigenTestHelpers_h_GUID_9C8A67BA_D846_4F94_8020_885E858600E3 32 #include "gtest/gtest.h" 39 (*os) <<
"[(" << quat.
vec().transpose() <<
"), " << quat.
w() <<
"]";
41 void PrintTo(Eigen::Vector3d
const &vec, ::std::ostream *os) {
42 (*os) << vec.transpose();
53 inline std::string
to_string(Eigen::Vector3d
const &vec) {
60 template <
typename Scalar, std::size_t SIZE,
typename Derived1,
64 for (std::size_t i = 0; i < SIZE; ++i) {
67 if (!lhs.AlmostEquals(rhs)) {
73 template <
typename Scalar,
typename T>
74 inline void formatStreamableValOrRowForMessage(std::ostream &os,
T &&val) {
75 os << std::setprecision(std::numeric_limits<Scalar>::digits10 + 2)
76 << std::forward<T>(val);
79 template <
typename Derived>
83 ::std::stringstream ss;
84 if (1 == vec.rows()) {
85 formatStreamableValOrRowForMessage<Scalar>(ss, vec);
87 formatStreamableValOrRowForMessage<Scalar>(ss, vec.
transpose());
92 template <
typename Derived>
96 ::std::stringstream ss;
98 formatStreamableValOrRowForMessage<Scalar>(ss, quat.
vec().transpose());
100 formatStreamableValOrRowForMessage<Scalar>(ss, quat.
w());
106 template <
typename Scalar>
111 if (compareVecsEq_impl<Scalar, 4>(expected.
coeffs(), actual.
coeffs())) {
112 return ::testing::AssertionSuccess();
114 return ::testing::internal::EqFailure(
115 expected_expression, actual_expression, formatQuatForMessage(expected),
116 formatQuatForMessage(actual),
false);
120 template <
typename Scalar>
125 if (!compareVecsEq_impl<Scalar, 4>(expected.
coeffs(), actual.
coeffs())) {
126 return ::testing::AssertionSuccess();
128 return ::testing::AssertionFailure()
129 <<
" Expected " << expected_expression <<
" ( " 130 << formatQuatForMessage(expected) <<
") != " << actual_expression
131 <<
"\n Got " << actual_expression <<
" = " 132 << formatQuatForMessage(actual) <<
" instead.";
135 template <
typename Derived1,
typename Derived2>
141 Derived1::IsVectorAtCompileTime,
142 "Expected must be a vector at compile time to use this assertion.");
144 Derived2::IsVectorAtCompileTime,
145 "Actual must be a vector at compile time to use this assertion.");
146 static_assert(Derived1::SizeAtCompileTime == Derived2::SizeAtCompileTime,
147 "Expected and Actual must be the same size vector at compile " 148 "time to use this assertion.");
151 template <
typename Scalar,
typename Derived1,
typename Derived2>
153 compareVecsEq(
const char *expected_expression,
const char *actual_expression,
156 checkVecStaticAssertions(expected, actual);
157 if (compareVecsEq_impl<Scalar, Derived1::SizeAtCompileTime>(expected,
159 return ::testing::AssertionSuccess();
162 return ::testing::internal::EqFailure(
163 expected_expression, actual_expression,
164 formatVectorForMessage(expected), formatVectorForMessage(actual),
168 template <
typename Scalar,
typename Derived1,
typename Derived2>
170 compareVecsNe(
const char *expected_expression,
const char *actual_expression,
173 checkVecStaticAssertions(expected, actual);
174 if (!compareVecsEq_impl<Scalar, Derived1::SizeAtCompileTime>(expected,
176 return ::testing::AssertionSuccess();
179 return ::testing::AssertionFailure()
180 <<
" Expected " << expected_expression <<
" ( " 181 << formatVectorForMessage(expected) <<
") != " << actual_expression
182 <<
"\n Got " << actual_expression <<
" = " 183 << formatVectorForMessage(actual) <<
" instead.";
185 ::testing::internal::EqFailure(
186 expected_expression, actual_expression,
187 ::testing::internal::StringStreamToString(&expected_ss),
188 ::testing::internal::StringStreamToString(&actual_ss),
false);
193 #define ASSERT_QUAT_DOUBLE_EQ(expected, actual) \ 194 ASSERT_PRED_FORMAT2(::EigenGTestCompareHelpers::compareQuatsEq<double>, \ 197 #define ASSERT_QUAT_DOUBLE_NE(expected, actual) \ 198 ASSERT_PRED_FORMAT2(::EigenGTestCompareHelpers::compareQuatsNe<double>, \ 200 #define ASSERT_VEC_DOUBLE_EQ(expected, actual) \ 201 ASSERT_PRED_FORMAT2(::EigenGTestCompareHelpers::compareVecsEq<double>, \ 203 #define ASSERT_VEC_DOUBLE_NE(expected, actual) \ 204 ASSERT_PRED_FORMAT2(::EigenGTestCompareHelpers::compareVecsNe<double>, \ 207 #endif // INCLUDED_EigenTestHelpers_h_GUID_9C8A67BA_D846_4F94_8020_885E858600E3 ::testing::AssertionResult compareQuatsEq(const char *expected_expression, const char *actual_expression, Eigen::Quaternion< Scalar > const &expected, Eigen::Quaternion< Scalar > const &actual)
based on CmpHelperFloatingPointEQ
Definition: EigenTestHelpers.h:108
const Coefficients & coeffs() const
Definition: Quaternion.h:93
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
const Block< const Coefficients, 3, 1 > vec() const
Definition: Quaternion.h:87
Eigen::Transpose< Derived > transpose()
Definition: Transpose.h:199
std::string to_string(Eigen::Quaterniond const &quat)
Helper to convert to string for messages.
Definition: EigenTestHelpers.h:46
const VectorBlock< const Coefficients, 3 > vec() const
Definition: Quaternion.h:78
Definition: ForwardDeclarations.h:233
Scalar w() const
Definition: Quaternion.h:75
::testing::AssertionResult compareVecsEq(const char *expected_expression, const char *actual_expression, Eigen::MatrixBase< Derived1 > const &expected, Eigen::MatrixBase< Derived2 > const &actual)
based on CmpHelperFloatingPointEQ
Definition: EigenTestHelpers.h:153
Definition: Quaternion.h:47
Definition: gtest.h:17669
::testing::AssertionResult compareQuatsNe(const char *expected_expression, const char *actual_expression, Eigen::Quaternion< Scalar > const &expected, Eigen::Quaternion< Scalar > const &actual)
based on CmpHelperFloatingPointEQ
Definition: EigenTestHelpers.h:122
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Scalar w() const
Definition: Quaternion.h:66
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
Definition: EigenTestHelpers.h:59