From 3545b114ab6d0719c76e317c01f25597b89f82dd Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Fri, 2 Aug 2013 15:21:36 +0000 Subject: [PATCH] Altered [CHECK|EXPECT]_DOUBLES_EQUAL such that nan values automatically cause the test to fail. The previous approach would always return pass if one of the compared values is nan, resulting in tests passing when they shouldn't. If you have a test where you want to check that the value is nan, use EXPECT(isnan(x));, where x is the value you want to test. --- CppUnitLite/Test.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppUnitLite/Test.h b/CppUnitLite/Test.h index 9f97757b6..82040dceb 100644 --- a/CppUnitLite/Test.h +++ b/CppUnitLite/Test.h @@ -130,7 +130,7 @@ boost::lexical_cast(actualTemp))); return; } } #define DOUBLES_EQUAL(expected,actual,threshold)\ { double actualTemp = actual; \ double expectedTemp = expected; \ - if (fabs ((expectedTemp)-(actualTemp)) > threshold) \ + if (isnan(actualTemp) || isnan(expectedTemp) || fabs ((expectedTemp)-(actualTemp)) > threshold) \ { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ boost::lexical_cast((double)expectedTemp), boost::lexical_cast((double)actualTemp))); return; } } @@ -150,7 +150,7 @@ boost::lexical_cast(actualTemp))); } } #define EXPECT_DOUBLES_EQUAL(expected,actual,threshold)\ { double actualTemp = actual; \ double expectedTemp = expected; \ - if (fabs ((expectedTemp)-(actualTemp)) > threshold) \ + if (isnan(actualTemp) || isnan(expectedTemp) || fabs ((expectedTemp)-(actualTemp)) > threshold) \ { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ boost::lexical_cast((double)expectedTemp), boost::lexical_cast((double)actualTemp))); } }