提交 e8d585b9 编写于 作者: J John Van Enk

Merge pull request #12 from rryles/master

Improved support for special floating point values
...@@ -28,6 +28,9 @@ const char* UnityStrDelta = " Values Not Within Delta "; ...@@ -28,6 +28,9 @@ const char* UnityStrDelta = " Values Not Within Delta ";
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless."; const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL"; const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual = " Actual pointer was NULL"; const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
const char* UnityStrInf = "Infinity";
const char* UnityStrNegInf = "Negative Infinity";
const char* UnityStrNaN = "NaN";
// compiler-generic print formatting masks // compiler-generic print formatting masks
const _U_UINT UnitySizeMask[] = const _U_UINT UnitySizeMask[] =
...@@ -536,7 +539,9 @@ void UnityAssertEqualFloatArray(const _UF* expected, ...@@ -536,7 +539,9 @@ void UnityAssertEqualFloatArray(const _UF* expected,
tol = UNITY_FLOAT_PRECISION * *ptr_expected; tol = UNITY_FLOAT_PRECISION * *ptr_expected;
if (tol < 0.0) if (tol < 0.0)
tol = 0.0 - tol; 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); UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement); UnityPrint(UnityStrElement);
...@@ -578,8 +583,8 @@ void UnityAssertFloatsWithin(const _UF delta, ...@@ -578,8 +583,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
...@@ -595,6 +600,75 @@ void UnityAssertFloatsWithin(const _UF delta, ...@@ -595,6 +600,75 @@ void UnityAssertFloatsWithin(const _UF delta,
} }
} }
//-----------------------------------------------
void UnityAssertFloatIsInf(const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((1.0f / 0.0f) != actual)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrint(UnityStrInf);
UnityPrint(UnityStrWas);
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertFloatIsNegInf(const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((-1.0f / 0.0f) != actual)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrint(UnityStrNegInf);
UnityPrint(UnityStrWas);
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertFloatIsNaN(const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if (actual == actual)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrint(UnityStrNaN);
UnityPrint(UnityStrWas);
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#endif //not UNITY_EXCLUDE_FLOAT #endif //not UNITY_EXCLUDE_FLOAT
//----------------------------------------------- //-----------------------------------------------
...@@ -631,7 +705,9 @@ void UnityAssertEqualDoubleArray(const _UD* expected, ...@@ -631,7 +705,9 @@ void UnityAssertEqualDoubleArray(const _UD* expected,
tol = UNITY_DOUBLE_PRECISION * *ptr_expected; tol = UNITY_DOUBLE_PRECISION * *ptr_expected;
if (tol < 0.0) if (tol < 0.0)
tol = 0.0 - tol; 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); UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement); UnityPrint(UnityStrElement);
...@@ -673,7 +749,8 @@ void UnityAssertDoublesWithin(const _UD delta, ...@@ -673,7 +749,8 @@ void UnityAssertDoublesWithin(const _UD delta,
pos_delta = 0.0f - pos_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); UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE #ifdef UNITY_DOUBLE_VERBOSE
...@@ -689,6 +766,75 @@ void UnityAssertDoublesWithin(const _UD delta, ...@@ -689,6 +766,75 @@ void UnityAssertDoublesWithin(const _UD delta,
} }
} }
//-----------------------------------------------
void UnityAssertDoubleIsInf(const _UD actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((1.0 / 0.0) != actual)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrint(UnityStrInf);
UnityPrint(UnityStrWas);
UnityPrintFloat((float)actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertDoubleIsNegInf(const _UD actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if ((-1.0 / 0.0) != actual)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrint(UnityStrNegInf);
UnityPrint(UnityStrWas);
UnityPrintFloat((float)actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
//-----------------------------------------------
void UnityAssertDoubleIsNaN(const _UD actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if (actual == actual)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE
UnityPrint(UnityStrExpected);
UnityPrint(UnityStrNaN);
UnityPrint(UnityStrWas);
UnityPrintFloat((float)actual);
#else
UnityPrint(UnityStrDelta);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#endif // not UNITY_EXCLUDE_DOUBLE #endif // not UNITY_EXCLUDE_DOUBLE
//----------------------------------------------- //-----------------------------------------------
......
...@@ -142,12 +142,17 @@ ...@@ -142,12 +142,17 @@
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL)
//Double (If Enabled) //Double (If Enabled)
#define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_DOUBLE(expected, actual) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE(expected, actual) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL)
//------------------------------------------------------- //-------------------------------------------------------
// Test Asserts (with additional messages) // Test Asserts (with additional messages)
...@@ -223,10 +228,15 @@ ...@@ -223,10 +228,15 @@
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, message)
//Double (If Enabled) //Double (If Enabled)
#define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_DOUBLE_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_DOUBLE_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, message)
#define TEST_ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, message) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, message)
#endif #endif
...@@ -410,6 +410,18 @@ void UnityAssertEqualFloatArray(const _UF* expected, ...@@ -410,6 +410,18 @@ void UnityAssertEqualFloatArray(const _UF* expected,
const _UU32 num_elements, const _UU32 num_elements,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsInf(const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsNegInf(const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsNaN(const _UF actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif #endif
#ifndef UNITY_EXCLUDE_DOUBLE #ifndef UNITY_EXCLUDE_DOUBLE
...@@ -424,6 +436,18 @@ void UnityAssertEqualDoubleArray(const _UD* expected, ...@@ -424,6 +436,18 @@ void UnityAssertEqualDoubleArray(const _UD* expected,
const _UU32 num_elements, const _UU32 num_elements,
const char* msg, const char* msg,
const UNITY_LINE_TYPE lineNumber); const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsInf(const _UD actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsNegInf(const _UD actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsNaN(const _UD actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif #endif
//------------------------------------------------------- //-------------------------------------------------------
...@@ -493,20 +517,32 @@ void UnityAssertEqualDoubleArray(const _UD* expected, ...@@ -493,20 +517,32 @@ void UnityAssertEqualDoubleArray(const _UD* expected,
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#else #else
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#endif #endif
#ifdef UNITY_EXCLUDE_DOUBLE #ifdef UNITY_EXCLUDE_DOUBLE
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#else #else
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UF)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UF)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#endif #endif
#endif #endif
...@@ -2237,6 +2237,168 @@ void testFloatsNotEqualActualNaN(void) ...@@ -2237,6 +2237,168 @@ void testFloatsNotEqualActualNaN(void)
#endif #endif
} }
void testFloatsNotEqualExpectedNaN(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 85.963f);
VERIFY_FAILS_END
#endif
}
void testFloatsNotEqualBothNaN(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 0.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testFloatsNotEqualInfNaN(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 0.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testFloatsNotEqualNaNInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 1.0f / 0.0f);
VERIFY_FAILS_END
#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 testFloatIsInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
TEST_ASSERT_FLOAT_IS_INF(2.0f / 0.0f);
TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / 0.0f);
#endif
}
void testFloatIsNotInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_INF(2.0f);
VERIFY_FAILS_END
#endif
}
void testFloatIsNotNegInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NEG_INF(-999.876f);
VERIFY_FAILS_END
#endif
}
void testFloatIsNan(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
TEST_ASSERT_FLOAT_IS_NAN(0.0f / 0.0f);
#endif
}
void testFloatIsNotNan(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NAN(234.9f);
VERIFY_FAILS_END
#endif
}
void testFloatInfIsNotNan(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NAN(1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testFloatNanIsNotInf(void)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_INF(0.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testEqualFloatArrays(void) void testEqualFloatArrays(void)
{ {
#ifdef UNITY_EXCLUDE_FLOAT #ifdef UNITY_EXCLUDE_FLOAT
...@@ -2367,6 +2529,34 @@ void testNotEqualFloatArraysNegative3(void) ...@@ -2367,6 +2529,34 @@ void testNotEqualFloatArraysNegative3(void)
#endif #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 ================== // ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ==================
void testDoublesWithinDelta(void) void testDoublesWithinDelta(void)
...@@ -2438,6 +2628,179 @@ void testDoublesNotEqualNegative2(void) ...@@ -2438,6 +2628,179 @@ void testDoublesNotEqualNegative2(void)
#endif #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 testDoubleIsInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
TEST_ASSERT_DOUBLE_IS_INF(2.0f / 0.0f);
TEST_ASSERT_DOUBLE_IS_NEG_INF(-3.0f / 0.0f);
#endif
}
void testDoubleIsNotInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_INF(2.0f);
VERIFY_FAILS_END
#endif
}
void testDoubleIsNotNegInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_NEG_INF(-999.876f);
VERIFY_FAILS_END
#endif
}
void testDoubleIsNan(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
TEST_ASSERT_DOUBLE_IS_NAN(0.0f / 0.0f);
#endif
}
void testDoubleIsNotNan(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_NAN(234.9f);
VERIFY_FAILS_END
#endif
}
void testDoubleInfIsNotNan(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_NAN(1.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testDoubleNanIsNotInf(void)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_INF(0.0f / 0.0f);
VERIFY_FAILS_END
#endif
}
void testEqualDoubleArrays(void) void testEqualDoubleArrays(void)
{ {
#ifdef UNITY_EXCLUDE_DOUBLE #ifdef UNITY_EXCLUDE_DOUBLE
...@@ -2568,3 +2931,30 @@ void testNotEqualDoubleArraysNegative3(void) ...@@ -2568,3 +2931,30 @@ void testNotEqualDoubleArraysNegative3(void)
#endif #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.
先完成此消息的编辑!
想要评论请 注册