From 194f17cbbf3284762536fdee1ae54f1f5efb89dd Mon Sep 17 00:00:00 2001 From: Gennadiy Rozental Date: Fri, 23 Feb 2007 18:20:10 +0000 Subject: [PATCH] Merged garbage removeal from trunk to branch [SVN r37051] --- example/unit_test_example_01.cpp | 65 +++++++++++++------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/example/unit_test_example_01.cpp b/example/unit_test_example_01.cpp index 0438a3c5..1cfa3928 100644 --- a/example/unit_test_example_01.cpp +++ b/example/unit_test_example_01.cpp @@ -1,52 +1,39 @@ -#include +// (C) Copyright Gennadiy Rozental 2005. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) -namespace ieee_754 { +// See http://www.boost.org/libs/test for the library home page. -template -struct decoded { - typedef long long mantissa_holder_type; - typedef short exponent_holder_type; +// Boost.Test - bool p_sign; - mantissa_holder_type p_mantissa; - exponent_holder_type p_exponent; -}; +// each test module could contain no more then one 'main' file with init function defined +// alternatively you could define init function yourself +#define BOOST_TEST_MAIN +#include -//___________________________________________________________________________// +//____________________________________________________________________________// -void decode( double v, decoded& d ) +// most frequently you implement test cases as a free functions with automatic registration +BOOST_AUTO_TEST_CASE( test1 ) { - union { - double v; - long long m; - } tmp; - - tmp.v = v; - - d.p_sign = !(tmp.m & 0x8000000000000000LL); - d.p_mantissa = tmp.m & 0x000FFFFFFFFFFFFFLL; - d.p_exponent = (short)((tmp.m & 0x7FF0000000000000LL) >> 52) - 1075; - - if( d.p_exponent != 0 ) - d.p_mantissa |= 0x0010000000000000LL; + // reports 'error in "test1": test 2 == 1 failed' + BOOST_CHECK( 2 == 1 ); } -//___________________________________________________________________________// +//____________________________________________________________________________// -} // namespace ieee_754 - -using namespace ieee_754; - -int -main() +// each test file may contain any number of test cases; each test case has to have unique name +BOOST_AUTO_TEST_CASE( test2 ) { - double d = 0.2; - decoded dec; + int i = 0; - decode( d, dec ); + // reports 'error in "test2": check i == 2 failed [0 != 2]' + BOOST_CHECK_EQUAL( i, 2 ); - std::cout << "orig = " << std::hex << *(long long*)&d << std::endl; - std::cout << "dec.p_sign = " << (dec.p_sign ? '+' : '-') << std::endl; - std::cout << "dec.p_mantissa = " << std::hex << dec.p_mantissa << std::endl; - std::cout << "dec.p_exponent = " << std::dec << dec.p_exponent << std::endl; + BOOST_CHECK_EQUAL( i, 0 ); } + +//____________________________________________________________________________// + +// EOF