1 #include <cppunit/TestAssert.h>
2 #include <cppunit/portability/FloatingPoint.h>
8 assertDoubleEquals( double expected,
11 SourceLine sourceLine,
12 const std::string &message )
14 AdditionalMessage msg( "Delta : " +
15 assertion_traits<double>::toString(delta) );
16 msg.addDetail( AdditionalMessage(message) );
19 if ( floatingPointIsFinite(expected) && floatingPointIsFinite(actual) )
20 equal = fabs( expected - actual ) <= delta;
23 // If expected or actual is not finite, it may be +inf, -inf or NaN (Not a Number).
24 // Value of +inf or -inf leads to a true equality regardless of delta if both
25 // expected and actual have the same value (infinity sign).
26 // NaN Value should always lead to a failed equality.
27 if ( floatingPointIsUnordered(expected) || floatingPointIsUnordered(actual) )
29 equal = false; // expected or actual is a NaN
31 else // ordered values, +inf or -inf comparison
33 equal = expected == actual;
37 Asserter::failNotEqualIf( !equal,
38 assertion_traits<double>::toString(expected),
39 assertion_traits<double>::toString(actual),
42 "double equality assertion failed" );