[boost.test] Floating point comparisons
Hi, I'm using boost.test and BOOST_CHECK_CLOSE to verify that some matrices I compute are equal to some reference matices. This works fine as long as no entries are zero in either matrix (reference or computed). However, when an entry is zero, BOOST_CHECK_CLOSE always fails, which makes sense, since relative error is undefined in such cases. If either entry is zero, I can use BOOST_CHECK_SMALL instead with an absolute error: if (ref==0.0 || val==0.0) BOOST_CHECK_SMALL(ref - val, absolute_error); else BOOST_CHECK_CLOSE(ref, val, relative_error); But is this really the best way to do this? And if this is the standard way of doing this, shouldn't there be function in boost.test for automating this, like: BOOST_CHECK_NEAR(ref, value, relative_error, absolute_error); kinds regards, Anders (sorry if this post appears twice)
Anders Wang Kristensen
If either entry is zero, I can use BOOST_CHECK_SMALL instead with an absolute error:
if (ref==0.0 || val==0.0) BOOST_CHECK_SMALL(ref - val, absolute_error); else BOOST_CHECK_CLOSE(ref, val, relative_error);
But is this really the best way to do this?
Looks reasonable
And if this is the standard way of doing this, shouldn't there be function in boost.test for automating this, like: BOOST_CHECK_NEAR(ref, value, relative_error, absolute_error);
This may or may not be generally useful. And it does not write specifica variation you need for yourself. Gennadiy
Hi. When linking i got a similar problem as the 2005 following thread : http://lists.boost.org/boost-users/2005/12/16037.php aka : multiple definition of `boost::test_tools::(anonymous namespace)::check_is_small' multiple definition of `boost::unit_test::(anonymous namespace)::unit_test_log' multiple definition of `boost::test_tools::(anonymous namespace)::check_is_close' multiple definition of `CoreTestSuite::LanguageInterfaceTestSuite::TestCase1::test_method()' multiple definition of `boost::test_tools::(anonymous namespace)::dummy_cond' Is there any known solution for what, according to the thread, seems to be a compiler bug ? Thanks. Gui
participants (3)
-
Anders Wang Kristensen
-
Gennadiy Rozental
-
Guillaume Theraud