From 83148364a541b1fc75caed56a301cd03489f65bb Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Tue, 30 Oct 2012 09:00:45 +0000 Subject: [PATCH] Fix For Issue #10 - TEST_ASSERT_EQUAL_FLOAT doesn't fail if actual value is a NaN. --- src/unity.c | 3 ++- test/testunity.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 0219b37..3787591 100644 --- a/src/unity.c +++ b/src/unity.c @@ -578,7 +578,8 @@ void UnityAssertFloatsWithin(const _UF delta, pos_delta = 0.0f - pos_delta; } - if (pos_delta < diff) + // NOTE: This comparrison is deliberately this way round so that NaNs fail. + if ( ! (pos_delta >= diff) ) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE diff --git a/test/testunity.c b/test/testunity.c index e98ca8f..ddd80c5 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -2226,6 +2226,17 @@ void testFloatsNotEqualNegative2(void) #endif } +void testFloatsNotEqualActualNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(85.963f, 0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + void testEqualFloatArrays(void) { #ifdef UNITY_EXCLUDE_FLOAT -- GitLab