From 933cc973645e3a59ad165af1b3b15487ccd63439 Mon Sep 17 00:00:00 2001 From: jsalling Date: Wed, 28 Sep 2016 22:53:15 -0500 Subject: [PATCH] Add option to set NaN != NaN for floating point assertions --- src/unity.c | 9 +++++++-- test/tests/testunity.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/unity.c b/src/unity.c index 58e93db..765e4e4 100644 --- a/src/unity.c +++ b/src/unity.c @@ -619,12 +619,17 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, /* Wrap this define in a function with variable types as float or double */ #define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \ if (isinf(expected) && isinf(actual) && (isneg(expected) == isneg(actual))) return 1; \ - if (isnan(expected) && isnan(actual)) return 1; \ + if (UNITY_NAN_CHECK) return 1; \ diff = actual - expected; \ if (diff < 0.0f) diff = 0.0f - diff; \ if (delta < 0.0f) delta = 0.0f - delta; \ - return !(isnan(diff) || isinf(diff) || (delta < diff)); + return !(isnan(diff) || isinf(diff) || (diff > delta)) /* This first part of this condition will catch any NaN or Infinite values */ +#ifndef UNITY_NAN_NOT_EQUAL_NAN + #define UNITY_NAN_CHECK isnan(expected) && isnan(actual) +#else + #define UNITY_NAN_CHECK 0 +#endif #ifndef UNITY_EXCLUDE_FLOAT static int UnityFloatsWithin(_UF delta, _UF expected, _UF actual) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 8230163..e66de4d 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3713,7 +3713,7 @@ void testNotEqualDoubleArraysNegative3(void) #endif } -void testNotEqualDoubleArraysNaN(void) +void testEqualDoubleArraysNaN(void) { #ifdef UNITY_EXCLUDE_DOUBLE TEST_IGNORE(); -- GitLab