14 #include <boost/test/unit_test.hpp>
29 #define CHECK_CLOSE_REL(val, ref, reltol) \
30 BOOST_CHECK(Acts::Test::checkCloseRel((val), (ref), (reltol)))
34 #define CHECK_CLOSE_ABS(val, ref, abstol) \
35 BOOST_CHECK(Acts::Test::checkCloseAbs((val), (ref), (abstol)))
39 #define CHECK_SMALL(val, small) \
40 BOOST_CHECK(Acts::Test::checkSmall((val), (small)))
45 #define CHECK_CLOSE_OR_SMALL(val, ref, reltol, small) \
46 BOOST_CHECK(Acts::Test::checkCloseOrSmall((val), (ref), (reltol), (small)))
53 #define CHECK_CLOSE_COVARIANCE(val, ref, tol) \
54 BOOST_CHECK(Acts::Test::checkCloseCovariance((val), (ref), (tol)))
60 namespace float_compare_internal {
83 res.message() <<
"The floating point value " << val;
84 if ((
std::abs(ref) < small) || (reltol == 0.)) {
85 res.message() <<
" is above small-ness threshold " << small;
87 res.message() <<
" is not within relative tolerance " << reltol
88 <<
" of reference " << ref;
104 res.message() <<
"The floating point value " << val
105 <<
" is not within absolute tolerance " << abstol
106 <<
" of reference " << ref <<
'.';
114 template <
typename Derived1,
typename Derived2>
116 const Eigen::DenseBase<Derived2>& ref,
118 constexpr
int rows1 = Eigen::DenseBase<Derived1>::RowsAtCompileTime;
119 constexpr
int rows2 = Eigen::DenseBase<Derived2>::RowsAtCompileTime;
120 constexpr
int cols1 = Eigen::DenseBase<Derived1>::ColsAtCompileTime;
121 constexpr
int cols2 = Eigen::DenseBase<Derived2>::ColsAtCompileTime;
123 if constexpr (rows1 != Eigen::Dynamic && rows2 != Eigen::Dynamic &&
124 cols1 != Eigen::Dynamic && cols2 != Eigen::Dynamic) {
126 static_assert(rows1 == rows2,
127 "Input matrices do not have the same number of rows");
128 static_assert(cols1 == cols2,
129 "Input matrices do not have the same number of columns");
132 if (val.rows() != ref.rows() || val.cols() != ref.cols()) {
134 res.message() <<
"Mismatch in matrix dimensions:\n" << val <<
"\n" << ref;
140 for (
int col = 0;
col < val.cols(); ++
col) {
141 for (
int row = 0; row < val.rows(); ++row) {
144 res.message() <<
" The failure occured during a matrix comparison,"
145 <<
" at index (" << row <<
", " <<
col <<
")."
146 <<
" The value was\n"
148 <<
"and the reference was\n"
162 template <
typename Container,
163 typename Enable =
typename Container::const_iterator>
168 size_t numVals = std::distance(std::cbegin(val), std::cend(val));
169 size_t numRefs = std::distance(std::cbegin(ref), std::cend(ref));
170 if (numVals != numRefs) {
172 res.message() <<
"The container size does not match (value has " << numVals
173 <<
" elements, reference has " << numRefs <<
" elements).";
179 auto valBeg = std::cbegin(val);
180 auto valIter = valBeg;
181 auto valEnd = std::cend(val);
182 auto refIter = std::cbegin(ref);
183 while (valIter != valEnd) {
187 res.message() <<
" The failure occured during a container comparison,"
188 <<
" at index " << std::distance(valBeg, valIter) <<
'.'
189 <<
" The value contained {";
190 for (
const auto& item : val) {
191 res.message() <<
' ' << item <<
' ';
193 res.message() <<
"} and the reference contained {";
194 for (
const auto& item : ref) {
195 res.message() <<
' ' << item <<
' ';
197 res.message() <<
"}.";
209 template <
typename T,
typename U>
211 const Eigen::DenseBase<U>& ref,
213 return matrixCompare(val.eval(), ref.eval(), std::move(compareImpl));
219 return matrixCompare(val.matrix(), ref.matrix(), std::move(compareImpl));
225 return compareImpl(val, ref);
231 template <
typename T,
typename U>
234 using namespace float_compare_internal;
238 template <
typename T,
typename U>
241 using namespace float_compare_internal;
245 template <
typename T>
247 using namespace float_compare_internal;
251 template <
typename T,
typename U>
256 using namespace float_compare_internal;
260 template <
typename Scalar,
int dim>
264 static_assert(
dim != Eigen::Dynamic,
265 "Dynamic-size matrices are currently unsupported.");
268 for (
int row =
col; row <
dim; ++row) {
277 auto orderOfMagnitude = std::sqrt(ref(row, row) * ref(
col,
col));
278 if (
std::abs(val(row,
col) - ref(row,
col)) >= tol * orderOfMagnitude) {
280 res.message() <<
"The difference between the covariance matrix term "
281 << val(row,
col) <<
" and its reference " << ref(row,
col)
283 <<
" at index (" << row <<
", " <<
col <<
"),"
284 <<
" is not within tolerance " << tol <<
'.'
285 <<
" The covariance matrix being tested was\n"
287 <<
"and the reference covariance matrix was\n"