Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / UnitTests / cppunit / src / cppunit / TestAssert.cpp
1 #include <cppunit/TestAssert.h>
2 #include <cppunit/portability/FloatingPoint.h>
3
4 CPPUNIT_NS_BEGIN
5
6
7 void 
8 assertDoubleEquals( 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
46 CPPUNIT_NS_END