~ubuntu-branches/ubuntu/vivid/psi/vivid

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/src/cppunit/TestAssert.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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