From 0d30a2aec28085cfb9fe359c321c289609b884ca Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Sat, 24 Feb 2007 20:13:04 +0000 Subject: Src/cppunit/TestAssert. 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 . * 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(). --- examples/cppunittest/CppUnitTestMain.dsp | 8 +++++++ examples/cppunittest/TestAssertTest.cpp | 37 +++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/cppunittest/CppUnitTestMain.dsp b/examples/cppunittest/CppUnitTestMain.dsp index 517fd2e..9b32154 100644 --- a/examples/cppunittest/CppUnitTestMain.dsp +++ b/examples/cppunittest/CppUnitTestMain.dsp @@ -176,6 +176,14 @@ PostBuild_Cmds=$(TargetPath) # PROP Default_Filter "" # 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 # Begin Source File diff --git a/examples/cppunittest/TestAssertTest.cpp b/examples/cppunittest/TestAssertTest.cpp index 3b621ed..e05c54e 100644 --- a/examples/cppunittest/TestAssertTest.cpp +++ b/examples/cppunittest/TestAssertTest.cpp @@ -1,6 +1,8 @@ #include "CoreSuite.h" #include "TestAssertTest.h" +#include #include +#include /* Note: @@ -192,16 +194,45 @@ TestAssertTest::testAssertDoubleEqualsPrecision() CPPUNIT_FAIL( "Expected assertion failure" ); } + void TestAssertTest::testAssertDoubleNonFinite() { double inf = std::numeric_limits::infinity(); + double nan = std::numeric_limits::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 ) ); - - double nan = std::numeric_limits::quiet_NaN(); - CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, 0.0, 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 ) ); CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, nan, 1.0 ) ); -- cgit v1.2.1