提交 2ab2fef6 编写于 作者: R Ross Ryles

Array comparisons of floating point types fail if any values are NaN or infinite.

上级 5853e24e
......@@ -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
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册