mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-07-15 00:52:46 +08:00
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.
This commit is contained in:
@ -618,7 +618,8 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
|
|||||||
/*-----------------------------------------------*/
|
/*-----------------------------------------------*/
|
||||||
/* Wrap this define in a function with variable types as float or double */
|
/* Wrap this define in a function with variable types as float or double */
|
||||||
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
|
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
|
||||||
if (expected == actual) return 1; \
|
if (isinf(expected) && isinf(actual) && (isneg(expected) == isneg(actual))) return 1; \
|
||||||
|
if (isnan(expected) && isnan(actual)) return 1; \
|
||||||
diff = actual - expected; \
|
diff = actual - expected; \
|
||||||
if (diff < 0.0f) diff = 0.0f - diff; \
|
if (diff < 0.0f) diff = 0.0f - diff; \
|
||||||
if (delta < 0.0f) delta = 0.0f - delta; \
|
if (delta < 0.0f) delta = 0.0f - delta; \
|
||||||
|
@ -18,20 +18,26 @@ void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking t
|
|||||||
|
|
||||||
#define VERIFY_FAILS_END \
|
#define VERIFY_FAILS_END \
|
||||||
} \
|
} \
|
||||||
Unity.CurrentTestFailed = (Unity.CurrentTestFailed == 1) ? 0 : 1; \
|
Unity.CurrentTestFailed = (Unity.CurrentTestFailed != 0) ? 0 : 1; \
|
||||||
if (Unity.CurrentTestFailed == 1) { \
|
if (Unity.CurrentTestFailed == 1) { \
|
||||||
SetToOneMeanWeAlreadyCheckedThisGuy = 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'); \
|
UNITY_OUTPUT_CHAR('\n'); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define VERIFY_IGNORES_END \
|
#define VERIFY_IGNORES_END \
|
||||||
} \
|
} \
|
||||||
Unity.CurrentTestFailed = (Unity.CurrentTestIgnored == 1) ? 0 : 1; \
|
Unity.CurrentTestFailed = (Unity.CurrentTestIgnored != 0) ? 0 : 1; \
|
||||||
Unity.CurrentTestIgnored = 0; \
|
Unity.CurrentTestIgnored = 0; \
|
||||||
if (Unity.CurrentTestFailed == 1) { \
|
if (Unity.CurrentTestFailed == 1) { \
|
||||||
SetToOneMeanWeAlreadyCheckedThisGuy = 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'); \
|
UNITY_OUTPUT_CHAR('\n'); \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +56,7 @@ void tearDown(void)
|
|||||||
TEST_FAIL_MESSAGE("<= Failed in tearDown");
|
TEST_FAIL_MESSAGE("<= Failed in tearDown");
|
||||||
if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
|
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');
|
UNITY_OUTPUT_CHAR('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2797,14 +2797,12 @@ void testFloatsNotEqualExpectedNaN(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testFloatsNotEqualBothNaN(void)
|
void testFloatsEqualBothNaN(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
EXPECT_ABORT_BEGIN
|
|
||||||
TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 0.0f / f_zero);
|
TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 0.0f / f_zero);
|
||||||
VERIFY_FAILS_END
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3192,7 +3190,7 @@ void testNotEqualFloatArraysNegative3(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testNotEqualFloatArraysNaN(void)
|
void testEqualFloatArraysNaN(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
@ -3200,9 +3198,7 @@ void testNotEqualFloatArraysNaN(void)
|
|||||||
float p0[] = {1.0f, 0.0f / f_zero, 25.4f, 0.253f};
|
float p0[] = {1.0f, 0.0f / f_zero, 25.4f, 0.253f};
|
||||||
float p1[] = {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);
|
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4);
|
||||||
VERIFY_FAILS_END
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3325,14 +3321,12 @@ void testDoublesNotEqualExpectedNaN(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testDoublesNotEqualBothNaN(void)
|
void testDoublesEqualBothNaN(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_DOUBLE
|
#ifdef UNITY_EXCLUDE_DOUBLE
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
EXPECT_ABORT_BEGIN
|
|
||||||
TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 0.0 / d_zero);
|
TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 0.0 / d_zero);
|
||||||
VERIFY_FAILS_END
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3727,9 +3721,7 @@ void testNotEqualDoubleArraysNaN(void)
|
|||||||
double p0[] = {1.0, 0.0 / d_zero, 25.4, 0.253};
|
double p0[] = {1.0, 0.0 / d_zero, 25.4, 0.253};
|
||||||
double p1[] = {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);
|
TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
|
||||||
VERIFY_FAILS_END
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user