diff options
author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2007-02-24 20:13:04 +0000 |
---|---|---|
committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2007-02-24 20:13:04 +0000 |
commit | 0d30a2aec28085cfb9fe359c321c289609b884ca (patch) | |
tree | d5848b1cb981a9fa5ba351b5eb01e4a0e06e1cf8 /examples | |
parent | 3ca9c5d071cb8162c89fd514a6116ee6b450d763 (diff) |
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 <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().
Diffstat (limited to 'examples')
-rw-r--r-- | examples/cppunittest/CppUnitTestMain.dsp | 8 | ||||
-rw-r--r-- | examples/cppunittest/TestAssertTest.cpp | 37 |
2 files changed, 42 insertions, 3 deletions
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 <cppunit/portability/FloatingPoint.h> #include <algorithm> +#include <limits> /* Note: @@ -192,16 +194,45 @@ TestAssertTest::testAssertDoubleEqualsPrecision() CPPUNIT_FAIL( "Expected assertion failure" ); } + 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 ) ); - - double nan = std::numeric_limits<double>::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 ) ); |