![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
BOOST_<level>_CLOSEBoost , Boost.Test , Reference API for writing tests
|
![]() |
Note |
---|---|
Требуется, чтобы левый и правый параметры были одного и того же типа плавающей точки. Вам нужно будет четко решить любое несоответствие типов, чтобы выбрать, какой тип использовать для сравнения. |
![]() |
Note |
---|---|
Обратите внимание, что для использования этих инструментов вам необходимо включить дополнительный заголовок< |
Код |
---|
<#defineBOOST_TEST_MODULEexample #include<boost/test/included/unit_test.hpp> #include<boost/test/floating_point_comparison.hpp> BOOST_AUTO_TEST_CASE(test) { doublev1=1.23456e-10; doublev2=1.23457e-10; BOOST_CHECK_CLOSE(v1,v2,0.0001); // Absolute value of difference between these two values is 1e-15. They seems // to be very close. But we want to checks that these values differ no more then 0.0001% // of their value. And this test will fail at tolerance supplied. }> |
выход |
---|
<>example Running1testcase... test.cpp(12):errorin"test":differencebetweenv1{1.23456e-010}andv2{1.23457e-010}exceeds0.0001% ***1failuresisdetectedintestsuite"example"> |
Код |
---|
<#defineBOOST_TEST_MODULEexample #include<boost/test/included/unit_test.hpp> #include<boost/test/floating_point_comparison.hpp> BOOST_AUTO_TEST_CASE(test) { doublev1=1.23456e28; doublev2=1.23457e28; BOOST_REQUIRE_CLOSE(v1,v2,0.001); // Absolute value of difference between these two values is 1e+23. // But we are interested only that it does not exeed 0.001% of a values compared // And this test will pass. }> |
выход |
---|
<>example Running1testcase... ***Noerrorsdetected> |
Смотрите также:
Статья BOOST_<level>_CLOSE раздела Boost.Test Reference API for writing tests может быть полезна для разработчиков на c++ и boost.
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.
:: Главная :: Reference API for writing tests ::
реклама |