Problem with BOOST_CHECK_CLOSE_FRACTION

﹥>﹥吖頭↗ 提交于 2019-12-04 07:44:27

After some testing, it turns out that the documentation for BOOST_CHECK_CLOSE_FRACTION is incorrect. The tolerance should be specified as a fraction of the expected value.

So, TFAE:

BOOST_CHECK(abs(x - y) < (min(x, y) * 0.1));
BOOST_CHECK_CLOSE(x, y, 10);
BOOST_CHECK_CLOSE_FRACTION(x, y, 0.1);

It is a problem with how you are using boost.

The last argument is a percent tolerance, not an absolute variance value. 5% of 0.4 is 0.02.

Obviously BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION won't work if you check if something is near 0. Then you can use:

BOOST_CHECK(abs(x - y) < accurancy);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!