提交 899f2f2f 编写于 作者: R Ross Ryles

UnityAssertFloatsWithin now fails any test where either a NaN or Infinite...

UnityAssertFloatsWithin now fails any test where either a NaN or Infinite value is passed as expected or actual.
上级 ae18c560
...@@ -578,8 +578,8 @@ void UnityAssertFloatsWithin(const _UF delta, ...@@ -578,8 +578,8 @@ void UnityAssertFloatsWithin(const _UF delta,
pos_delta = 0.0f - pos_delta; pos_delta = 0.0f - pos_delta;
} }
// NOTE: This comparison is deliberately this way round so that NaNs fail. //This first part of this condition will catch any NaN or Infinite values
if ( ! (pos_delta >= diff) ) if ((diff * 0.0f != 0.0f) || (pos_delta < diff))
{ {
UnityTestResultsFailBegin(lineNumber); UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE #ifdef UNITY_FLOAT_VERBOSE
......
...@@ -2281,6 +2281,50 @@ void testFloatsNotEqualNaNInf(void) ...@@ -2281,6 +2281,50 @@ void testFloatsNotEqualNaNInf(void)
#endif #endif
} }
void testFloatsNotEqualActualInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(321.642f, 1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testFloatsNotEqualExpectedInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 321.642f);
VERIFY_FAILS_END
#endif
}
void testFloatsNotEqualBothInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testFloatsNotEqualPlusMinusInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, -1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testEqualFloatArrays(void) void testEqualFloatArrays(void)
{ {
#ifdef UNITY_EXCLUDE_FLOAT #ifdef UNITY_EXCLUDE_FLOAT
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册