提交 dce6d329 编写于 作者: M Mark VanderVoord

Finished fixing floating point comparisons. We have streamlined how floats and...

Finished fixing floating point comparisons. We have streamlined how floats and doubles are checked, but we still can't compare them for equality directly. So we're directly testing for infinite and NaN before checking diffs. Also, we've officially decided that for testing purposes NaN shall equal NaN, +Inf shall equal +Inf, and -Inf shall equal -Inf. It's what most people expect during a test.
上级 0f07adfa
......@@ -617,11 +617,12 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
/*-----------------------------------------------*/
/* Wrap this define in a function with variable types as float or double */
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
if (expected == actual) return 1; \
diff = actual - expected; \
if (diff < 0.0f) diff = 0.0f - diff; \
if (delta < 0.0f) delta = 0.0f - delta; \
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
if (isinf(expected) && isinf(actual) && (isneg(expected) == isneg(actual))) return 1; \
if (isnan(expected) && isnan(actual)) return 1; \
diff = actual - expected; \
if (diff < 0.0f) diff = 0.0f - diff; \
if (delta < 0.0f) delta = 0.0f - delta; \
return !(isnan(diff) || isinf(diff) || (delta < diff));
/* This first part of this condition will catch any NaN or Infinite values */
......
......@@ -18,20 +18,26 @@ void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking t
#define VERIFY_FAILS_END \
} \
Unity.CurrentTestFailed = (Unity.CurrentTestFailed == 1) ? 0 : 1; \
Unity.CurrentTestFailed = (Unity.CurrentTestFailed != 0) ? 0 : 1; \
if (Unity.CurrentTestFailed == 1) { \
SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
UnityPrint("[[[[ Previous Test Should Have Failed But Did Not ]]]]"); \
UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
UNITY_OUTPUT_CHAR(':'); \
UnityPrint(Unity.CurrentTestName); \
UnityPrint(":FAIL: [[[[ Test Should Have Failed But Did Not ]]]]"); \
UNITY_OUTPUT_CHAR('\n'); \
}
#define VERIFY_IGNORES_END \
} \
Unity.CurrentTestFailed = (Unity.CurrentTestIgnored == 1) ? 0 : 1; \
Unity.CurrentTestFailed = (Unity.CurrentTestIgnored != 0) ? 0 : 1; \
Unity.CurrentTestIgnored = 0; \
if (Unity.CurrentTestFailed == 1) { \
SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
UnityPrint("[[[[ Previous Test Should Have Ignored But Did Not ]]]]"); \
UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
UNITY_OUTPUT_CHAR(':'); \
UnityPrint(Unity.CurrentTestName); \
UnityPrint(":FAIL: [[[[ Test Should Have Ignored But Did Not ]]]]"); \
UNITY_OUTPUT_CHAR('\n'); \
}
......@@ -50,7 +56,7 @@ void tearDown(void)
TEST_FAIL_MESSAGE("<= Failed in tearDown");
if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
{
UnityPrint("[[[[ Previous Test Should Have Passed But Did Not ]]]]");
UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]");
UNITY_OUTPUT_CHAR('\n');
}
}
......
......@@ -2797,14 +2797,12 @@ void testFloatsNotEqualExpectedNaN(void)
#endif
}
void testFloatsNotEqualBothNaN(void)
void testFloatsEqualBothNaN(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 0.0f / f_zero);
VERIFY_FAILS_END
#endif
}
......@@ -3192,7 +3190,7 @@ void testNotEqualFloatArraysNegative3(void)
#endif
}
void testNotEqualFloatArraysNaN(void)
void testEqualFloatArraysNaN(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
......@@ -3200,9 +3198,7 @@ void testNotEqualFloatArraysNaN(void)
float p0[] = {1.0f, 0.0f / f_zero, 25.4f, 0.253f};
float p1[] = {1.0f, 0.0f / f_zero, 25.4f, 0.253f};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4);
VERIFY_FAILS_END
#endif
}
......@@ -3325,14 +3321,12 @@ void testDoublesNotEqualExpectedNaN(void)
#endif
}
void testDoublesNotEqualBothNaN(void)
void testDoublesEqualBothNaN(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 0.0 / d_zero);
VERIFY_FAILS_END
#endif
}
......@@ -3727,9 +3721,7 @@ void testNotEqualDoubleArraysNaN(void)
double p0[] = {1.0, 0.0 / d_zero, 25.4, 0.253};
double p1[] = {1.0, 0.0 / d_zero, 25.4, 0.253};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
VERIFY_FAILS_END
#endif
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册