?????????

??????????????? “??????” ?????????????????BOOST_CHECK ??????????????????????? Boost ??? output_test_stream ??????????????????????е? run.log??????? output_test_stream??C/C++ ?????????????????? output_test_stream ?????????????????? match_pattern ??????嵥 7 ???????????

?????嵥 7. ????????????????????

#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
using boost::test_tools::output_test_stream;
BOOST_AUTO_TEST_SUITE ( test )
BOOST_AUTO_TEST_CASE( test )
{
output_test_stream output( "run.log"?? true );
output << predefined_user_func( );
BOOST_CHECK( output.match_pattern() );
}
BOOST_AUTO_TEST_SUITE_END( )

??????????

???????????м????????????????????? ?嵥 8??????????????? — ???????濴????????

?????嵥 8. ??Ч???????

#define BOOST_TEST_MODULE floatingTest
#include <boost/test/included/unit_test.hpp>
#include <cmath>
BOOST_AUTO_TEST_SUITE ( test )
BOOST_AUTO_TEST_CASE( test )
{
float f1 = 567.0102;
float result = sqrt(f1); // this could be my_sqrt; faster implementation
// for some specific DSP like hardware
BOOST_CHECK(f1 == result * result);
}
BOOST_AUTO_TEST_SUITE_END( )

????????????????????????????????????????????? sqrt ??????BOOST_CHECK ????????????????????????????????????????? — f1 ?? result*result ??С?????????λ??????????????????Boost ??????ó??????? BOOST_WARN_CLOSE_FRACTION??BOOST_CHECK_CLOSE_FRACTION ?? BOOST_REQUIRE_CLOSE_FRACTION ????????????????????????????? Boost ???? floating_point_comparison.hpp????????????????????????????????? check ???壨?? ?嵥 9????

?????嵥 9. BOOST_CHECK_CLOSE_FRACTION ?????

????BOOST_CHECK_CLOSE_FRACTION (left-value?? right-value?? tolerance-limit);

?????嵥 9 ???????? BOOST_CHECK????????? BOOST_CHECK_CLOSE_FRACTION ?????????????? 0.0001???嵥 10 ?????????????????????

?????嵥 10. ??Ч???????

#define BOOST_TEST_MODULE floatingTest
#include <boost/test/included/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include <cmath>
BOOST_AUTO_TEST_SUITE ( test )
BOOST_AUTO_TEST_CASE( test )
{
float f1 = 567.01012;
float result = sqrt(f1); // this could be my_sqrt; faster implementation
// for some specific DSP like hardware
BOOST_CHECK_CLOSE_FRACTION (f1?? result * result?? 0.0001);
}
BOOST_AUTO_TEST_SUITE_END( )

??????δ???????????????????? ?嵥 10 ?е?????????? 0.0000001???嵥 11 ???????????