mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 08:25:58 +01:00
Array comparisons of floating point types fail if any values are NaN or infinite.
This commit is contained in:
@@ -539,7 +539,9 @@ void UnityAssertEqualFloatArray(const _UF* expected,
|
||||
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
|
||||
if (tol < 0.0)
|
||||
tol = 0.0 - tol;
|
||||
if (diff > tol)
|
||||
|
||||
//This first part of this condition will catch any NaN or Infinite values
|
||||
if ((diff * 0.0f != 0.0f) || (diff > tol))
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
@@ -703,7 +705,9 @@ void UnityAssertEqualDoubleArray(const _UD* expected,
|
||||
tol = UNITY_DOUBLE_PRECISION * *ptr_expected;
|
||||
if (tol < 0.0)
|
||||
tol = 0.0 - tol;
|
||||
if (diff > tol)
|
||||
|
||||
//This first part of this condition will catch any NaN or Infinite values
|
||||
if ((diff * 0.0f != 0.0f) || (diff > tol))
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
|
||||
@@ -2529,6 +2529,34 @@ void testNotEqualFloatArraysNegative3(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void testNotEqualFloatArraysNaN(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
float p0[] = {1.0, 0.0 / 0.0, 25.4, 0.253};
|
||||
float p1[] = {1.0, 0.0 / 0.0, 25.4, 0.253};
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4);
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
void testNotEqualFloatArraysInf(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
float p0[] = {1.0, 1.0 / 0.0, 25.4, 0.253};
|
||||
float p1[] = {1.0, 1.0 / 0.0, 25.4, 0.253};
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4);
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ==================
|
||||
|
||||
void testDoublesWithinDelta(void)
|
||||
@@ -2903,3 +2931,30 @@ void testNotEqualDoubleArraysNegative3(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void testNotEqualDoubleArraysNaN(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_DOUBLE
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
double p0[] = {1.0, 0.0 / 0.0, 25.4, 0.253};
|
||||
double p1[] = {1.0, 0.0 / 0.0, 25.4, 0.253};
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
void testNotEqualDoubleArraysInf(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_DOUBLE
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
double p0[] = {1.0, 1.0 / 0.0, 25.4, 0.253};
|
||||
double p1[] = {1.0, 1.0 / 0.0, 25.4, 0.253};
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user