Add macros for testing inequalities between floats, doubles

This commit is contained in:
Jonathan Reichelt Gjertsen
2021-05-24 14:53:29 +02:00
parent 27ef0eb44e
commit 410de1a02b
7 changed files with 559 additions and 0 deletions

View File

@@ -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,