[Cppunit-cvs] cppunit/include/cppunit TestAssert.h,1.25,1.26
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2004-11-06 09:07:07
|
Update of /cvsroot/cppunit/cppunit/include/cppunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3470/include/cppunit Modified Files: TestAssert.h Log Message: * include/cppunit/TestAssert.h: integrated Neil Ferguson patch for high precision conversion to string for double number. Modified the patch to works even if DBL_DIG C99 macro is not defined. Index: TestAssert.h =================================================================== RCS file: /cvsroot/cppunit/cppunit/include/cppunit/TestAssert.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** TestAssert.h 5 Nov 2004 22:47:20 -0000 1.25 --- TestAssert.h 6 Nov 2004 09:05:45 -0000 1.26 *************** *** 7,10 **** --- 7,12 ---- #include <cppunit/portability/Stream.h> + #include <float.h> // For struct assertion_traits<double> + CPPUNIT_NS_BEGIN *************** *** 51,54 **** --- 53,86 ---- + /*! \brief Traits used by CPPUNIT_ASSERT_DOUBLES_EQUAL(). + * + * This specialisation from @c struct @c assertion_traits<> ensures that + * doubles are converted in full, instead of being rounded to the default + * 6 digits of precision. Use the system defined ISO C99 macro DBL_DIG + * within float.h is available to define the maximum precision, otherwise + * use the hard-coded maximum precision of 15. + */ + template <> + struct assertion_traits<double> + { + static bool equal( double x, double y ) + { + return x == y; + } + + static std::string toString( double x ) + { + #ifdef DBL_DIG + const int precision = DBL_DIG; + #else + const int precision = 15; + #endif // #ifdef DBL_DIG + char buffer[128]; + sprintf(buffer, "%.*g", DBL_DIG, x); + return buffer; + } + }; + + /*! \brief (Implementation) Asserts that two objects of the same type are equals. * Use CPPUNIT_ASSERT_EQUAL instead of this function. |