mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-12-16 12:28:39 +08:00
Add macros for testing inequalities between floats, doubles
This commit is contained in:
56
src/unity.c
56
src/unity.c
@@ -968,6 +968,34 @@ void UnityAssertFloatsWithin(const UNITY_FLOAT delta,
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
void UnityAssertGreaterOrLessFloat(const UNITY_FLOAT threshold,
|
||||
const UNITY_FLOAT actual,
|
||||
const UNITY_COMPARISON_T compare,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
RETURN_IF_FAIL_OR_IGNORE;
|
||||
|
||||
int failed = 0;
|
||||
|
||||
// Checking for "not success" rather than failure to get the right result for NaN
|
||||
if (!(actual < threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; }
|
||||
if (!(actual > threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; }
|
||||
|
||||
if (failed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintFloat(actual);
|
||||
if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); }
|
||||
if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); }
|
||||
UnityPrintFloat(threshold);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
void UnityAssertFloatSpecial(const UNITY_FLOAT actual,
|
||||
const char* msg,
|
||||
@@ -1108,6 +1136,34 @@ void UnityAssertDoublesWithin(const UNITY_DOUBLE delta,
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
void UnityAssertGreaterOrLessDouble(const UNITY_DOUBLE threshold,
|
||||
const UNITY_DOUBLE actual,
|
||||
const UNITY_COMPARISON_T compare,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
RETURN_IF_FAIL_OR_IGNORE;
|
||||
|
||||
int failed = 0;
|
||||
|
||||
// Checking for "not success" rather than failure to get the right result for NaN
|
||||
if (!(actual < threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; }
|
||||
if (!(actual > threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; }
|
||||
|
||||
if (failed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintFloat(actual);
|
||||
if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); }
|
||||
if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); }
|
||||
UnityPrintFloat(threshold);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
|
||||
const char* msg,
|
||||
|
||||
Reference in New Issue
Block a user