File: patch04.assert-doubles-equal

package info (click to toggle)
cppunit 1.12.1-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 5,136 kB
  • ctags: 3,387
  • sloc: cpp: 18,307; sh: 9,213; ansic: 2,973; makefile: 480; xml: 58; csh: 6
file content (48 lines) | stat: -rw-r--r-- 2,249 bytes parent folder | download
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
47
48
? cppunit.pc
Index: examples/cppunittest/TestAssertTest.cpp
===================================================================
RCS file: /cvsroot/cppunit/cppunit/examples/cppunittest/TestAssertTest.cpp,v
retrieving revision 1.9
diff -u -b -B -r1.9 TestAssertTest.cpp
--- examples/cppunittest/TestAssertTest.cpp	5 Nov 2004 22:47:21 -0000	1.9
+++ examples/cppunittest/TestAssertTest.cpp	11 Nov 2006 04:39:10 -0000
@@ -167,6 +167,17 @@
 
   CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.1, 1.2, 0.09 ) );
   CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.09 ) );
+
+  double inf = std::numeric_limits<double>::infinity();
+  CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, 0.0, 1.0 ) );
+  CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, inf, 1.0 ) );
+  CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, inf, 1.0 ) );
+
+  double nan = std::numeric_limits<double>::quiet_NaN();
+  CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, 0.0, 1.0 ) );
+  CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, nan, 1.0 ) );
+  CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, inf, 1.0 ) );
+  CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, nan, 1.0 ) );
 }
 
 
Index: src/cppunit/TestAssert.cpp
===================================================================
RCS file: /cvsroot/cppunit/cppunit/src/cppunit/TestAssert.cpp,v
retrieving revision 1.12
diff -u -b -B -r1.12 TestAssert.cpp
--- src/cppunit/TestAssert.cpp	5 Nov 2004 22:47:20 -0000	1.12
+++ src/cppunit/TestAssert.cpp	11 Nov 2006 04:39:10 -0000
@@ -21,7 +21,13 @@
                          assertion_traits<double>::toString(delta) );
   msg.addDetail( AdditionalMessage(message) );
 
-  Asserter::failNotEqualIf( fabs( expected - actual ) > delta,
+  bool equal;
+  if ( isfinite(expected) && isfinite(actual) )
+      equal = fabs( expected - actual ) <= delta;
+  else
+      equal = expected == actual;
+
+  Asserter::failNotEqualIf( !equal,
                             assertion_traits<double>::toString(expected),
                             assertion_traits<double>::toString(actual),
                             sourceLine,