[Cppunit-cvs] cppunit/src/cppunit TestAssert.cpp, 1.13, 1.14 cppunit.dsp, 1.54, 1.55
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2007-02-24 21:13:12
|
Update of /cvsroot/cppunit/cppunit/src/cppunit In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9552/src/cppunit Modified Files: TestAssert.cpp cppunit.dsp Log Message: * src/cppunit/TestAssert.cpp (assertDoubleEquals): Moved finite & NaN tests to include/cppunit/portability/FloatingPoint.h. Changed implementation assertDoubleEquals to explicitly test for NaN in case of non-finite values to force equality failure in the presence of NaN. Previous implementation failed on Microsoft Visual Studio 6 (on this platform: NaN == NaN). * examples/cppunittest/TestAssertTest.cpp: Add more unit tests to test the portable floating-point primitive. Added missing include <limits>. * include/cppunit/portability/Makefile.am: * include/cppunit/portability/FloatingPoint.h: Added file. Extracted isfinite() from TestAssert.cpp. * include/cppunit/config-evc4: * include/cppunit/config-msvc6: Added support for _finite(). Index: cppunit.dsp =================================================================== RCS file: /cvsroot/cppunit/cppunit/src/cppunit/cppunit.dsp,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** cppunit.dsp 13 Oct 2005 20:35:50 -0000 1.54 --- cppunit.dsp 24 Feb 2007 21:13:04 -0000 1.55 *************** *** 248,251 **** --- 248,255 ---- # Begin Source File + SOURCE=..\..\include\cppunit\portability\FloatingPoint.h + # End Source File + # Begin Source File + SOURCE=..\..\include\cppunit\Portability.h # End Source File Index: TestAssert.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit/src/cppunit/TestAssert.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TestAssert.cpp 27 Jan 2007 05:45:08 -0000 1.13 --- TestAssert.cpp 24 Feb 2007 21:13:04 -0000 1.14 *************** *** 1,18 **** #include <cppunit/TestAssert.h> ! ! #include <math.h> ! ! #if !defined(CPPUNIT_HAVE_ISFINITE) ! ! static inline bool isfinite( double x ) ! { ! #if defined(CPPUNIT_HAVE_FINITE) ! return finite( x ); ! #else ! return ( x * 0.0 ) == 0.0; ! #endif ! } ! ! #endif CPPUNIT_NS_BEGIN --- 1,4 ---- #include <cppunit/TestAssert.h> ! #include <cppunit/portability/FloatingPoint.h> CPPUNIT_NS_BEGIN *************** *** 31,38 **** bool equal; ! if ( isfinite(expected) && isfinite(actual) ) equal = fabs( expected - actual ) <= delta; else ! equal = expected == actual; Asserter::failNotEqualIf( !equal, --- 17,37 ---- bool equal; ! if ( floatingPointIsFinite(expected) && floatingPointIsFinite(actual) ) equal = fabs( expected - actual ) <= delta; else ! { ! // If expected or actual is not finite, it may be +inf, -inf or NaN (Not a Number). ! // Value of +inf or -inf leads to a true equality regardless of delta if both ! // expected and actual have the same value (infinity sign). ! // NaN Value should always lead to a failed equality. ! if ( floatingPointIsUnordered(expected) || floatingPointIsUnordered(actual) ) ! { ! equal = false; // expected or actual is a NaN ! } ! else // ordered values, +inf or -inf comparison ! { ! equal = expected == actual; ! } ! } Asserter::failNotEqualIf( !equal, |