#define BOOST_TEST_MODULE "main" #include <boost/test/unit_test.hpp> #include <boost/test/included/unit_test.hpp> #incldue "FtoC.h"
BOOST_AUTO_TEST_SUITE(f_to_c) // code goes here BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(basic_tests) { BOOST_TEST(0 == FtoC(32)); BOOST_TEST(100 == FtoC(212)); BOOST_TEST(32 == CtoF(0)); BOOST_TEST(212 == CtoF(100)); }
FtoCTest1: FtoC.o
BOOST_AUTO_TEST_CASE(errors) { BOOST_TEST(2 == FtoC(32)); BOOST_TEST(100 > FtoC(212)); BOOST_TEST(32 < CtoF(0), "0c is not less than 32f"); BOOST_TEST(false, " Boolean test failed"); }
void DoALoopTest() { double dc = 5.0/9.0; double df = 1.0; double cent; double f = 32.0; double tmp; for(cent = 0; cent <= 100; cent += dc) { tmp = CtoF(static_cast<float>(cent)); BOOST_TEST(f == tmp); f += df; } return; } BOOST_AUTO_TEST_CASE(Loop_Through_C_test) { DoALoopTest(); }
f = 32.0; for(cent = 0; cent > -100; cent -=dc) { tmp = CtoF(static_cast<float>(cent)); BOOST_TEST(f == tmp, tolerance(0.001) ); f -= df; }
FtoCTest2.cpp(30): error: in "f_to_c/Loop_Through_C_test": check f == tmp has failed [16 != 15.999999046325684] FtoCTest2.cpp(30): error: in "f_to_c/Loop_Through_C_test": check f == tmp has failed [12 != 12.000000953674316]
using namespace boost::test_tools; ... BOOST_TEST(f == tmp, tolerance(0.001) );