开发者

Formatting for failure output of BOOST_CHECK_CLOSE?

I am adding tests to legacy code using the boost test framework.

One such test might be

double expectedPrice = /*...local computation*/
BOOST_CHECK_CLOSE(expectedPrice, object->price, ACCURACY_THRESHOLD);

Where expectedPrice is a double co开发者_高级运维mputed locally and the object is retrieved from the system under test.

error in "MyTest": difference{0.21097%} between expectedPrice{4.7300000000000004} and object->price{4.7400000000000002} exceeds 1.0000000000000001e-05%

Of course, that is a little hard to read, given all the decimals. Any way to have the test output formatted better/differently given that I am using naked doubles and not some other type?


This is known issue. With known solution. Just a bit hard to implement, though I still hope to do at some point. Meanwhile you are stuck with whatever output your iostream library produces.


You could try:

cout << setprecision(2)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜