-2

I would like to use the BOOST_TEST machinery to compare mathematical vector types using plain (in)equality operators.

I can only find how to tell Boost.Test that it should do that for a type (by specializing boost::math::fpc::tolerance_based for that type), given the presence of the usual arithmetic and comparison operators, but I can't tell it to do the comparison in a specific way (I'd like the element-wise comparison here, and only really need (in)equality, no less/greater etc.).

Is there any customization point for this functionality? If not, how can I easily enable such behaviour only in my tests?

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • 2
    Eigen has an ```isApprox``` method that accepts an error limit https://eigen.tuxfamily.org/dox/classEigen_1_1DenseBase.html#ae8443357b808cd393be1b51974213f9c – Homer512 Jun 25 '22 at 11:50
  • Right, but I want to have BOOST_TEST call that automatically when I do `BOOST_TEST(someEigenVector == MY_EXPECTED_VALUE)`, so my tests aren't riddled with specific code for comparisons when there is a test framework that implements floating point and container comparison functionality – rubenvb Jun 27 '22 at 09:35
  • `BOOST_TEST(((someEigenVector - targetEigenVector).array() <= tolerance).all())`...maybe. But something like that seems far uglier than just using `isApprox`. – Matt Jun 27 '22 at 13:33
  • Yes, but I want to write the simple equality and make BOOST_TEST use its builtin floating point/container comparison under the hood. Just like you can write BOOST_TEST(someFloat == 1.f) and it will do a tolerance-based comparison given the appropriate decorators. – rubenvb Jun 27 '22 at 14:18

1 Answers1

0

You can always write a custom operator that will do the comparison. For example:

bool operator == (const Vector3d &lhs, const double &rhs){
    return (lhs.array() == rhs).all();
}

My guess would be the authors of Eigen didn't include these because they provided the array class to give you access for element-wise operations. Also there are many ways to define inequalities like this and everyone will have a different set of requirements.

Matt
  • 2,554
  • 2
  • 24
  • 45