Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Boost tests #3426

Closed
jngrad opened this issue Jan 21, 2020 · 2 comments · Fixed by #3427
Closed

Fix Boost tests #3426

jngrad opened this issue Jan 21, 2020 · 2 comments · Fixed by #3427
Assignees
Labels

Comments

@jngrad
Copy link
Member

jngrad commented Jan 21, 2020

BOOST_CHECK_CLOSE takes a percentage as tolerance. Epsilon values must be multiplied by 100.

In this example, the first line is incorrect:

BOOST_CHECK_CLOSE(x * x, int_pow<2>(x), eps);
BOOST_CHECK_CLOSE((x * x) * (x * x), int_pow<4>(x), 100. * eps);

In this example, the line is correct:

BOOST_CHECK_CLOSE(interpolated_value, exact_value, 1.);

This affects both 4.1 and 4.2.

@jngrad jngrad added the Bug label Jan 21, 2020
@jngrad jngrad added this to the Espresso 4.1.3 milestone Jan 21, 2020
@jngrad jngrad self-assigned this Jan 21, 2020
@fweik
Copy link
Contributor

fweik commented Jan 21, 2020

I don't understand the boost documentation.

@jngrad
Copy link
Member Author

jngrad commented Jan 21, 2020

According to section tolerance-based comparisons, function BOOST_CHECK_CLOSE does a relative comparison and evaluates to assert(abs(x - y)/abs(x) <= tol && abs(x - y)/abs(y) <= tol) when both x and y are non-zero.

In the binary, ::boost::math::fpc::percent_tolerance(std::numeric_limits<double>::epsilon()) is used as the epsilon value, where percent_tolerance() divides by 100 while percent_tolerance_t() doesn't (according to section tolerance (decorator)). Here is a MWE:

#define BOOST_TEST_MODULE tolerance test
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
/* compile with g++ test.cc -lboost_unit_test_framework */
BOOST_AUTO_TEST_CASE(tolerance)
{
  BOOST_CHECK_CLOSE(1, 1.01 - 1e-8, 1); // passes: slightly less than 1%
  BOOST_CHECK_CLOSE(1, 1.01 + 1e-8, 1); // fails: slightly more than 1%
}

@kodiakhq kodiakhq bot closed this as completed in #3427 Jan 21, 2020
kodiakhq bot added a commit that referenced this issue Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants