![]() |
![]() ![]() ![]() ![]() |
![]() |
Enabling tolerance for user-defined typesBoost , Boost.Test , Floating point comparison
|
|||||||||||||||||||||||||||||||||||||||||||||||
|
Код |
|---|
<#defineBOOST_TEST_MODULEtolerance_04 #include<boost/test/included/unit_test.hpp> #include<boost/rational.hpp> namespaceutf=boost::unit_test; namespacett=boost::test_tools; namespaceboost{namespacemath{namespacefpc{ template<typenameI> structtolerance_based<rational<I>>:boost::true_type{}; }}} typedefboost::rational<int>ratio; BOOST_AUTO_TEST_CASE(test1,*utf::tolerance(ratio(1,1000))) { ratiox(1002,100);// 10.02 ratioy(1001,100);// 10.01 ratioz(1000,100);// 10.00 BOOST_TEST(x==y);// irrelevant diff by default BOOST_TEST(x==y,tt::tolerance(ratio(1,2000))); BOOST_TEST(x!=z);// relevant diff by default BOOST_TEST(x!=z,tt::tolerance(ratio(2,1000))); }> |
|
выход |
|---|
> tolerance_04 Running 1 test case... test.cpp(23): error: in "test1": check x == y has failed [501/50 != 1001/100]. Relative difference exceeds tolerance [1/1001 > 1/2000] test.cpp(26): error: in "test1": check x != z has failed [501/50 == 10/1]. Relative difference is within tolerance [1/501 < 1/500] *** 2 failures are detected in the test module "tolerance_04" |
ToleranceCompatible
<MoveConstructible>,<EqualityComparable>,<LessThanComparable>
< |
Тип, который является моделью< |
|
|
objects of type |
< |
objects of type |
|
Имя |
выражение |
Тип возврата |
|---|---|---|
Обращение от< |
< |
|
Добавление |
< |
< |
Вычитание |
< |
< |
|
Negation |
< |
< |
Умножение |
|
< |
Подразделение |
< |
< |
Смешанное равенство |
< |
< |
Смешанный заказ |
< |
< |
|
|
< |
Статья Enabling tolerance for user-defined types раздела Boost.Test Floating point comparison может быть полезна для разработчиков на c++ и boost.
:: Главная :: Floating point comparison ::
реклама |