Skip to content

Commit b2360fa

Browse files
committed
Adding delta infinity & nan checks & tests
1 parent 0963e20 commit b2360fa

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

src/unity.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,17 @@ void UnityAssertWithinFloatArray(const UNITY_FLOAT delta,
954954
#endif
955955
}
956956

957+
if (isinf(in_delta))
958+
{
959+
return; /* Arrays will be force equal with infinite delta */
960+
}
961+
962+
if (isnan(in_delta))
963+
{
964+
/* Delta must be correct number */
965+
UnityPrintPointlessAndBail();
966+
}
967+
957968
if (expected == actual)
958969
{
959970
return; /* Both are NULL or same pointer */
@@ -1170,6 +1181,17 @@ void UnityAssertWithinDoubleArray(const UNITY_DOUBLE delta,
11701181
#endif
11711182
}
11721183

1184+
if (isinf(in_delta))
1185+
{
1186+
return; /* Arrays will be force equal with infinite delta */
1187+
}
1188+
1189+
if (isnan(in_delta))
1190+
{
1191+
/* Delta must be correct number */
1192+
UnityPrintPointlessAndBail();
1193+
}
1194+
11731195
if (expected == actual)
11741196
{
11751197
return; /* Both are NULL or same pointer */

test/tests/test_unity_doubles.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,22 @@ void testDoubleArraysWithin(void)
10491049
#endif
10501050
}
10511051

1052+
void testDoubleArraysWithinUnusualDelta(void)
1053+
{
1054+
#ifdef UNITY_EXCLUDE_DOUBLE
1055+
TEST_IGNORE();
1056+
#else
1057+
double p0[] = {-INFINITY, -8.0, 25.4, -0.123};
1058+
double p1[] = {INFINITY, 10.1};
1059+
1060+
TEST_ASSERT_DOUBLE_ARRAY_WITHIN(INFINITY, p0, p1, 2);
1061+
1062+
EXPECT_ABORT_BEGIN
1063+
TEST_ASSERT_DOUBLE_ARRAY_WITHIN(NAN, p0, p0, 4);
1064+
VERIFY_FAILS_END
1065+
#endif
1066+
}
1067+
10521068
void testEqualDoubleEachEqual(void)
10531069
{
10541070
#ifdef UNITY_EXCLUDE_DOUBLE

test/tests/test_unity_floats.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,22 @@ void testFloatArraysWithin(void)
10471047
#endif
10481048
}
10491049

1050+
void testFloatArraysWithinUnusualDelta(void)
1051+
{
1052+
#ifdef UNITY_EXCLUDE_FLOAT
1053+
TEST_IGNORE();
1054+
#else
1055+
float p0[] = {(float)-INFINITY, -8.0f, 25.4f, -0.123f};
1056+
float p1[] = {(float)INFINITY, 10.1f};
1057+
1058+
TEST_ASSERT_FLOAT_ARRAY_WITHIN(INFINITY, p0, p1, 2);
1059+
1060+
EXPECT_ABORT_BEGIN
1061+
TEST_ASSERT_FLOAT_ARRAY_WITHIN(NAN, p0, p0, 4);
1062+
VERIFY_FAILS_END
1063+
#endif
1064+
}
1065+
10501066
void testEqualFloatEachEqual(void)
10511067
{
10521068
#ifdef UNITY_EXCLUDE_FLOAT

0 commit comments

Comments
 (0)