diff --git a/src/unity.c b/src/unity.c index 432c297..be3daaf 100644 --- a/src/unity.c +++ b/src/unity.c @@ -954,6 +954,17 @@ void UnityAssertWithinFloatArray(const UNITY_FLOAT delta, #endif } + if (isinf(in_delta)) + { + return; /* Arrays will be force equal with infinite delta */ + } + + if (isnan(in_delta)) + { + /* Delta must be correct number */ + UnityPrintPointlessAndBail(); + } + if (expected == actual) { return; /* Both are NULL or same pointer */ @@ -1170,6 +1181,17 @@ void UnityAssertWithinDoubleArray(const UNITY_DOUBLE delta, #endif } + if (isinf(in_delta)) + { + return; /* Arrays will be force equal with infinite delta */ + } + + if (isnan(in_delta)) + { + /* Delta must be correct number */ + UnityPrintPointlessAndBail(); + } + if (expected == actual) { return; /* Both are NULL or same pointer */ diff --git a/test/tests/test_unity_doubles.c b/test/tests/test_unity_doubles.c index 174f733..0ad9494 100644 --- a/test/tests/test_unity_doubles.c +++ b/test/tests/test_unity_doubles.c @@ -1049,6 +1049,22 @@ void testDoubleArraysWithin(void) #endif } +void testDoubleArraysWithinUnusualDelta(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + double p0[] = {-INFINITY, -8.0, 25.4, -0.123}; + double p1[] = {INFINITY, 10.1}; + + TEST_ASSERT_DOUBLE_ARRAY_WITHIN(INFINITY, p0, p1, 2); + + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_ARRAY_WITHIN(NAN, p0, p0, 4); + VERIFY_FAILS_END +#endif +} + void testEqualDoubleEachEqual(void) { #ifdef UNITY_EXCLUDE_DOUBLE diff --git a/test/tests/test_unity_floats.c b/test/tests/test_unity_floats.c index b86f480..9e92f96 100644 --- a/test/tests/test_unity_floats.c +++ b/test/tests/test_unity_floats.c @@ -1047,6 +1047,22 @@ void testFloatArraysWithin(void) #endif } +void testFloatArraysWithinUnusualDelta(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + float p0[] = {(float)-INFINITY, -8.0f, 25.4f, -0.123f}; + float p1[] = {(float)INFINITY, 10.1f}; + + TEST_ASSERT_FLOAT_ARRAY_WITHIN(INFINITY, p0, p1, 2); + + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_ARRAY_WITHIN(NAN, p0, p0, 4); + VERIFY_FAILS_END +#endif +} + void testEqualFloatEachEqual(void) { #ifdef UNITY_EXCLUDE_FLOAT