4

I expected this to compile properly:

#include <boost/test/unit_test.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/angle/degrees.hpp>

using boost::units::quantity;
using boost::units::degree::degrees;
using boost::units::degree::plane_angle;

int main() {
    quantity<plane_angle> q1 = 15 * degrees;

    BOOST_CHECK_CLOSE(q1, 15 * degrees, 1e-8);
    return 0;
}

Unfortunately this produces a couple hundreds lines of errors with GCC.

Of course I could do this instead.

BOOST_CHECK_CLOSE(q1.value(), 15, 1e-8);

But I would like to keep the units explicit in the test case, just in case that someone else decides to change the unit type of q1.

Is there any way to keep the unit explicit?

sbabbi
  • 11,070
  • 2
  • 29
  • 57
  • `15 * degrees` doesn't have the type you expect, try using `15.*degrees`. – alfC Sep 01 '15 at 18:54
  • I have had the same problem. BOOST_CHECK_EQUAL and BOOST_CHECK_LT etc... work but not CLOSE. It appears to be something like boost converting the values to integers in order to do the tolerance check – Simmovation Mar 14 '17 at 18:05

1 Answers1

0

One option is to divide the equal values and compare to 1:

BOOST_CHECK_CLOSE(q1 / (15 * degrees), 1, 1e-8);

When dividing boost::units::quantity by the same type, you end up with a dimensionless quantity, which is allows to be implicitly cast to double.

Jeffrey Faust
  • 547
  • 3
  • 12