问题BOOST_CHECK_CLOSE_FRACTION [英] Problem with BOOST_CHECK_CLOSE_FRACTION
本文介绍了问题BOOST_CHECK_CLOSE_FRACTION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了boost ::测试库,我试图检查的实际百分比值接近预期值:
I'm using the Boost::Test library, and I am trying to check if an actual percent value is close to the expected value:
BOOST_CHECK_CLOSE_FRACTION(
items[i].ExpectedPercent,
items[i].ActualCount / totalCount,
0.05);
由于某些原因,当值足够接近此检查甚至失败:
For some reason this check fails even when the values are close enough:
difference between items[i].ExpectedPercent{0.40000000000000002}
and items[i].ActualCount / totalReturned{0.42999999999999999}
exceeds 0.050000000000000003
这是用升压或问题一个问题,我如何使用Boost?
Is this a problem with Boost or a problem with how I am using Boost?
推荐答案
经过一番测试,事实证明,对于BOOST_CHECK_CLOSE_FRACTION的文档不正确。公差应指定为预期值的一小部分。
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.
所以,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);
这篇关于问题BOOST_CHECK_CLOSE_FRACTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文