mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-12-18 23:11:11 +08:00
Adding delta infinity & nan checks & tests
This commit is contained in:
22
src/unity.c
22
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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user