|
Boost Users : |
Subject: [Boost-users] [Units] Units in unit tests
From: Stephan Menzel (stephan.menzel_at_[hidden])
Date: 2017-05-07 14:08:48
Hello all,
please excuse the weird subject line. I have just introduced boost units as
length quantity for vectors into my project here.
What previously was:
typedef boost::qvm::vec<double, 3> vec3;
is now:
typedef boost::units::quantity<length, double> qlength;
typedef boost::qvm::vec<qlength, 3> vec3;
Which seems to work OK so far, I'm not done testing. While converting all
my unit tests I came to wonder is how this is best adopted.
I have lots of lines like:
vec3 v = get_some_value();
and then I test the individual component values like this:
BOOST_CHECK_CLOSE(X(v), 42.0, 0.001); // check for length of 42 meters
Now this would have to be rewritten to:
BOOST_CHECK_CLOSE(X(v).value(), 42.0, 0.001);
But doing this, I imply the length is in meters, right? Doesn't that defeat
the purpose a little? I feel this would be better:
BOOST_CHECK_CLOSE(X(v), 42.0 * meters, 0.001);
but the Macro won't accept this as this is not a floating point type
anymore.
Does anybody have some hint as to how this is best addressed while still
have maximum readability?
All my best...
Stephan
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net