1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-23 08:25:58 +01:00

Expanded NaN and Infinity handling to doubles.

This commit is contained in:
Ross Ryles
2012-10-30 16:12:50 +00:00
parent 899f2f2fab
commit b14819bc79
2 changed files with 101 additions and 1 deletions

View File

@@ -673,7 +673,8 @@ void UnityAssertDoublesWithin(const _UD delta,
pos_delta = 0.0f - pos_delta;
}
if (pos_delta < diff)
//This first part of this condition will catch any NaN or Infinite values
if ((diff * 0.0f != 0.0f) || (pos_delta < diff))
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE

View File

@@ -2526,6 +2526,105 @@ void testDoublesNotEqualNegative2(void)
#endif
}
void testDoublesNotEqualActualNaN(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(85.963f, 0.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testDoublesNotEqualExpectedNaN(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 85.963f);
VERIFY_FAILS_END
#endif
}
void testDoublesNotEqualBothNaN(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 0.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testDoublesNotEqualInfNaN(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 0.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testDoublesNotEqualNaNInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testDoublesNotEqualActualInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(321.642f, 1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testDoublesNotEqualExpectedInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 321.642f);
VERIFY_FAILS_END
#endif
}
void testDoublesNotEqualBothInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testDoublesNotEqualPlusMinusInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, -1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testEqualDoubleArrays(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE