Menu

[r558]: / trunk / cppunit / src / cppunit / TestAssert.cpp  Maximize  Restore  History

Download this file

47 lines (39 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cppunit/TestAssert.h>
#include <cppunit/portability/FloatingPoint.h>
CPPUNIT_NS_BEGIN
void
assertDoubleEquals( double expected,
double actual,
double delta,
SourceLine sourceLine,
const std::string &message )
{
AdditionalMessage msg( "Delta : " +
assertion_traits<double>::toString(delta) );
msg.addDetail( AdditionalMessage(message) );
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,
assertion_traits<double>::toString(expected),
assertion_traits<double>::toString(actual),
sourceLine,
msg,
"double equality assertion failed" );
}
CPPUNIT_NS_END
MongoDB Logo MongoDB