From 3108aba5c7541cc107f404202c2720439d2cbd15 Mon Sep 17 00:00:00 2001 From: jsalling Date: Tue, 23 Aug 2016 22:36:02 -0500 Subject: [PATCH] If two floats happen to be equal, return right away Covers the cases where infinity == infinity --- src/unity.c | 4 ++++ test/tests/testunity.c | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unity.c b/src/unity.c index 159e0d9..496183a 100644 --- a/src/unity.c +++ b/src/unity.c @@ -683,6 +683,8 @@ void UnityAssertFloatsWithin(const _UF delta, UNITY_SKIP_EXECUTION; + if (expected == actual) return; + if (diff < 0.0f) { diff = 0.0f - diff; @@ -844,6 +846,8 @@ void UnityAssertDoublesWithin(const _UD delta, UNITY_SKIP_EXECUTION; + if (expected == actual) return; + if (diff < 0.0) { diff = 0.0 - diff; diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 830dc57..f922b28 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -2838,9 +2838,7 @@ void testFloatsNotEqualBothInf(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, 1.0f / f_zero); - VERIFY_FAILS_END #endif } @@ -3370,9 +3368,7 @@ void testDoublesNotEqualBothInf(void) #ifdef UNITY_EXCLUDE_DOUBLE TEST_IGNORE(); #else - EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 1.0 / d_zero); - VERIFY_FAILS_END #endif }