Float comparisons in tests could use some standardization (was ACTS-531)
Original author Hadrien Benjamin Grasland @hgraslan
Currently, our tests compare floating-point quantities in many different ways:
BOOST_CHECK_CLOSE(x, y, tol)
BOOST_CHECK_CLOSE_FRACTION(x, y, tol)
BOOST_TEST(x == y[, tol])
BOOST_CHECK(x.isApprox(y[, tol])), optionally followed by a BOOST_CHECK_EQUAL(x, y).
checkCloseXyz(x, y)
Size check + element-wise container element comparisons
These methods have varying semantics (and, to be frank, all suck in some way):
- Some have tolerances expressed as a fraction (as is standard in physics), others use percentages.
- Some tolerate type heterogeneity (e.g. x is a double and y is a float), others error out when it happens.
- Some support Eigen types and STL containers, others error out when encountering anything but a certain type.
- Some mandate a tolerance to be explicitly specified, others either have it hardcoded or take it out of global state.
- Some report errors precisely, others only state that a comparison has failed in a rather unhelpful way.
- Some use relative comparisons that are unstable near zero, others (silently) fall back to absolute tolerances.
- Some operate on containers element-wise, others use a norm-base definition (e.g. ||x - ref|| < tol * ||ref||)
- Some treat one of the inputs as a privileged reference, others try to treat inputs symmetrically.
It would be nice if we could converge into something a bit more unified. Being partly responsible for this mess (I created method #5 (closed)), I have a prototype branche around which tries to make this happen, which I will submit soon-ish.
Edited by Moritz Kiehn