Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] Units in unit tests
From: Stephan Menzel (stephan.menzel_at_[hidden])
Date: 2017-05-08 07:11:34


Hello Gavin,

thanks for your response.

On Mon, May 8, 2017 at 4:17 AM, Gavin Lambert via Boost-users <
boost-users_at_[hidden]> wrote:

>
> I don't know if there is a better way to do this within the confines of
> Boost.Test itself (perhaps making a custom macro, or extending what the
> macro already does in some way),

I was suspecting this, just wanted to clarify. I guess I will create my own
wrappers then.

> but there *is* a better way to get basic values out of unit quantities
> rather than using .value().
>
> Instead of:
>
> BOOST_CHECK_CLOSE(X(v).value(), 42.0, 0.001);
>
> Try:
>
> BOOST_CHECK_CLOSE(X(v) / meters, 42.0, 0.001);
>
> (You might also need an explicit static_cast<double>. If so, you might
> want to wrap this whole thing in a helper method to reduce typing.)
>

OK, this is a bit of surprise. This "X(v) / meters" obviously means "I want
the value in meters"?
Actually I spent quite some time trying to figure that exact thing out and
I just couldn't find it in the docs. I have just tried it and it works.

Great, that's at least a way to make things explicit and helps.

Thanks,
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