MCPcopy Create free account
hub / github.com/FlightGear/flightgear / assertDoubleEquals

Function assertDoubleEquals

3rdparty/cppunit/src/cppunit/TestAssert.cpp:4–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <cppunit/portability/FloatingPoint.h>
3
4CPPUNIT_NS_BEGIN
5
6
7void
8assertDoubleEquals( double expected,
9 double actual,
10 double delta,
11 SourceLine sourceLine,
12 const std::string &message )
13{
14 AdditionalMessage msg( "Delta : " +
15 assertion_traits<double>::toString(delta) );
16 msg.addDetail( AdditionalMessage(message) );
17
18 bool equal;
19 if ( floatingPointIsFinite(expected) && floatingPointIsFinite(actual) )
20 equal = fabs( expected - actual ) <= delta;
21 else
22 {
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) )
28 {
29 equal = false; // expected or actual is a NaN
30 }
31 else // ordered values, +inf or -inf comparison
32 {
33 equal = expected == actual;
34 }
35 }
36
37 Asserter::failNotEqualIf( !equal,
38 assertion_traits<double>::toString(expected),
39 assertion_traits<double>::toString(actual),
40 sourceLine,
41 msg,
42 "double equality assertion failed" );
43}
44
45
46CPPUNIT_NS_END

Callers

nothing calls this directly

Calls 4

toStringFunction · 0.85
floatingPointIsFiniteFunction · 0.85
floatingPointIsUnorderedFunction · 0.85
addDetailMethod · 0.80

Tested by

no test coverage detected