Adding delta infinity & nan checks & tests

This commit is contained in:
AJIOB
2022-11-28 20:23:36 +03:00
parent 0963e20d0b
commit b2360fa7ca
3 changed files with 54 additions and 0 deletions

View File

@@ -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 */

View File

@@ -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

View File

@@ -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