unit test and BOOST_CHECK_CLOSE
dear list, When executing a test defined by: BOOST_CHECK_CLOSE(t3.x(3), 0.0, epsilon); I get the message: difference between t3.x(3){2.34188e-17} and 0.0{0} exceeds 1e-08% where obviously the difference does not exceeds the given threshold 1e-08... What's going on ? -- thomas
Hello Thomas, Thursday, February 17, 2005, 1:35:48 PM, you wrote: Thomas> dear list, Thomas> When executing a test defined by: Thomas> BOOST_CHECK_CLOSE(t3.x(3), 0.0, epsilon); Thomas> I get the message: Thomas> difference between t3.x(3){2.34188e-17} and 0.0{0} exceeds 1e-08% Thomas> where obviously the difference does not exceeds the given threshold 1e-08... Thomas> What's going on ? As I remember, tolerance should be given in percents. See http://www.boost.org/libs/test/doc/components/test_tools/floating_point_comp... for more detailed description of algorithm used in BOOST_CHECK_CLOSE. Either I do not understand something or you cannot use BOOST_CHECK_CLOSE for direct comparison with 0.0. Inequations given never satisfied in case one of arguments is zero. I think you could write BOOST_CHECK(t3.x(3) >= -epsilon && t3.x(3) <= epsilon); given that epsilon is non-negative. -- Best regards, Vladimir mailto:vkrasovsky@yandex.ru
"Thomas Lemaire"
dear list,
When executing a test defined by: BOOST_CHECK_CLOSE(t3.x(3), 0.0, epsilon);
I get the message: difference between t3.x(3){2.34188e-17} and 0.0{0} exceeds 1e-08%
where obviously the difference does not exceeds the given threshold 1e-08...
What's going on ?
-- thomas
I really should put this into FAQ section. This was discussed several times. The explanation lies in a fact that Boost.Test uses different algorithm (from the one you implicitly assumed) for FP values comparisons. Look into docs for more details. In this algorithm no value (but zero itself) is close enough to zero. I plan to implement BOOST_CHECK_SMALL macro that should be used instead for the checks like above. Be aware though that it may not be what you really want. Gennadiy
participants (3)
-
Gennadiy Rozental
-
Thomas Lemaire
-
Vladimir Krasovsky