Update of /cvsroot/cppunit/cppunit/examples/cppunittest
In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9552/examples/cppunittest
Modified Files:
CppUnitTestMain.dsp TestAssertTest.cpp
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: TestAssertTest.cpp
===================================================================
RCS file: /cvsroot/cppunit/cppunit/examples/cppunittest/TestAssertTest.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** TestAssertTest.cpp 31 Jan 2007 05:27:07 -0000 1.13
--- TestAssertTest.cpp 24 Feb 2007 21:13:04 -0000 1.14
***************
*** 1,5 ****
--- 1,7 ----
#include "CoreSuite.h"
#include "TestAssertTest.h"
+ #include <cppunit/portability/FloatingPoint.h>
#include <algorithm>
+ #include <limits>
/*
***************
*** 193,206 ****
}
void
TestAssertTest::testAssertDoubleNonFinite()
{
double inf = std::numeric_limits<double>::infinity();
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, 0.0, 1.0 ) );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, inf, 1.0 ) );
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, inf, 1.0 ) );
!
! double nan = std::numeric_limits<double>::quiet_NaN();
! CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, 0.0, 1.0 ) );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, nan, 1.0 ) );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, inf, 1.0 ) );
--- 195,237 ----
}
+
void
TestAssertTest::testAssertDoubleNonFinite()
{
double inf = std::numeric_limits<double>::infinity();
+ double nan = std::numeric_limits<double>::quiet_NaN();
+ // test our portable floating-point primitives that detect NaN values
+ CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsUnordered( nan ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( inf ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( -inf ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 1.0 ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 1.5 ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 2.0 ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 2.5 ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 0.0 ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( -1.0 ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( -2.0 ) );
+ // test our portable floating-point primitives that detect finite values
+ CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 0.0 ) );
+ CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 0.5 ) );
+ CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 1.0 ) );
+ CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 1.5 ) );
+ CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 2.0 ) );
+ CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 2.5 ) );
+ CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( -1.5 ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsFinite( nan ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsFinite( inf ) );
+ CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsFinite( -inf ) );
+ // Infinity tests
+ CPPUNIT_ASSERT( inf == inf );
+ CPPUNIT_ASSERT( -inf == -inf );
+ CPPUNIT_ASSERT( -inf != inf );
+ CPPUNIT_ASSERT( -inf < inf );
+ CPPUNIT_ASSERT( inf > -inf );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, 0.0, 1.0 ) );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, inf, 1.0 ) );
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, inf, 1.0 ) );
! // NaN tests
! CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, 0.0, 1.0 ) ); // this one fails
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, nan, 1.0 ) );
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, inf, 1.0 ) );
Index: CppUnitTestMain.dsp
===================================================================
RCS file: /cvsroot/cppunit/cppunit/examples/cppunittest/CppUnitTestMain.dsp,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** CppUnitTestMain.dsp 13 Oct 2005 20:35:51 -0000 1.27
--- CppUnitTestMain.dsp 24 Feb 2007 21:13:03 -0000 1.28
***************
*** 177,180 ****
--- 177,188 ----
# Begin Source File
+ SOURCE=.\assertion_traitsTest.cpp
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\assertion_traitsTest.h
+ # End Source File
+ # Begin Source File
+
SOURCE=.\ExceptionTest.cpp
# End Source File
|