11 #include <boost/test/unit_test.hpp>
30 #define CHECK_CLOSE_REL(val, ref, reltol) \
31 BOOST_CHECK(Acts::Test::checkCloseRel((val), (ref), (reltol)))
35 #define CHECK_CLOSE_ABS(val, ref, abstol) \
36 BOOST_CHECK(Acts::Test::checkCloseAbs((val), (ref), (abstol)))
40 #define CHECK_SMALL(val, small) \
41 BOOST_CHECK(Acts::Test::checkSmall((val), (small)))
46 #define CHECK_CLOSE_OR_SMALL(val, ref, reltol, small) \
47 BOOST_CHECK(Acts::Test::checkCloseOrSmall((val), (ref), (reltol), (small)))
54 #define CHECK_CLOSE_COVARIANCE(val, ref, tol) \
55 BOOST_CHECK(Acts::Test::checkCloseCovariance((val), (ref), (tol)))
61 namespace float_compare_internal {
74 if (std::abs(val -
ref) < reltol * std::abs(
ref)) {
77 }
else if (std::abs(val) <
small) {
84 res.message() <<
"The floating point value " << val;
85 if ((std::abs(
ref) < small) || (reltol == 0.)) {
86 res.message() <<
" is above small-ness threshold " <<
small;
88 res.message() <<
" is not within relative tolerance " << reltol
89 <<
" of reference " <<
ref;
99 if (std::abs(
ref - val) <= abstol) {
105 res.message() <<
"The floating point value " << val
106 <<
" is not within absolute tolerance " << abstol
107 <<
" of reference " <<
ref <<
'.';
115 template <
typename Derived1,
typename Derived2>
117 const Eigen::DenseBase<Derived2>&
ref,
119 constexpr
int rows1 = Eigen::DenseBase<Derived1>::RowsAtCompileTime;
120 constexpr
int rows2 = Eigen::DenseBase<Derived2>::RowsAtCompileTime;
121 constexpr
int cols1 = Eigen::DenseBase<Derived1>::ColsAtCompileTime;
122 constexpr
int cols2 = Eigen::DenseBase<Derived2>::ColsAtCompileTime;
124 if constexpr (rows1 != Eigen::Dynamic && rows2 != Eigen::Dynamic &&
125 cols1 != Eigen::Dynamic && cols2 != Eigen::Dynamic) {
127 static_assert(rows1 == rows2,
128 "Input matrices do not have the same number of rows");
129 static_assert(cols1 == cols2,
130 "Input matrices do not have the same number of columns");
133 if (val.rows() != ref.rows() || val.cols() != ref.cols()) {
135 res.message() <<
"Mismatch in matrix dimensions:\n" << val <<
"\n" <<
ref;
141 for (
int col = 0;
col < val.cols(); ++
col) {
142 for (
int row = 0; row < val.rows(); ++row) {
145 res.message() <<
" The failure occurred during a matrix comparison,"
146 <<
" at index (" << row <<
", " <<
col <<
")."
147 <<
" The value was\n"
149 <<
"and the reference was\n"
158 template <
typename T>
160 template <
typename T>
162 template <
typename T>
170 template <
typename Container,
171 typename = std::enable_if_t<
172 !Acts::Concepts::exists<has_eval_t, Container> &&
173 Acts::Concepts::exists<has_begin_t, Container> &&
174 Acts::Concepts::exists<has_end_t, Container>,
180 size_t numVals =
std::distance(std::cbegin(val), std::cend(val));
181 size_t numRefs =
std::distance(std::cbegin(ref), std::cend(ref));
182 if (numVals != numRefs) {
184 res.message() <<
"The container size does not match (value has " << numVals
185 <<
" elements, reference has " << numRefs <<
" elements).";
191 auto valBeg = std::cbegin(val);
192 auto valIter = valBeg;
193 auto valEnd = std::cend(val);
194 auto refIter = std::cbegin(ref);
195 while (valIter != valEnd) {
199 res.message() <<
" The failure occurred during a container comparison,"
201 <<
" The value contained {";
202 for (
const auto& item : val) {
203 res.message() <<
' ' << item <<
' ';
205 res.message() <<
"} and the reference contained {";
206 for (
const auto& item : ref) {
207 res.message() <<
' ' << item <<
' ';
209 res.message() <<
"}.";
221 template <
typename T,
typename U>
223 const Eigen::DenseBase<U>&
ref,
237 return compareImpl(val, ref);
243 template <
typename T,
typename U>
246 using namespace float_compare_internal;
250 template <
typename T,
typename U>
253 using namespace float_compare_internal;
257 template <
typename T>
259 using namespace float_compare_internal;
263 template <
typename T,
typename U>
268 using namespace float_compare_internal;
272 template <
typename val_t,
typename ref_t>
274 const Eigen::MatrixBase<val_t>& val,
const Eigen::MatrixBase<ref_t>&
ref,
276 EIGEN_STATIC_ASSERT_FIXED_SIZE(val_t);
277 EIGEN_STATIC_ASSERT_FIXED_SIZE(ref_t);
278 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(val_t, ref_t);
279 assert(val.cols() == val.rows());
280 assert(ref.cols() == ref.rows());
282 for (
int col = 0;
col < val.cols(); ++
col) {
283 for (
int row =
col; row < val.rows(); ++row) {
292 auto orderOfMagnitude = std::sqrt(
ref(row, row) *
ref(
col,
col));
293 if (std::abs(val(row,
col) -
ref(row,
col)) >= tol * orderOfMagnitude) {
295 res.message() <<
"The difference between the covariance matrix term "
296 << val(row,
col) <<
" and its reference " <<
ref(row,
col)
298 <<
" at index (" << row <<
", " <<
col <<
"),"
299 <<
" is not within tolerance " << tol * orderOfMagnitude
300 <<
'.' <<
" The covariance matrix being tested was\n"
302 <<
"and the reference covariance matrix was\n"