Add LESS_OR_EQUAL and GREATER_OR_EQUAL assertions for doubles and floats

This commit is contained in:
Jonathan Reichelt Gjertsen
2021-12-03 20:38:09 +01:00
parent 2a8f3fe65a
commit b732fbf1ca
7 changed files with 471 additions and 0 deletions

View File

@@ -1015,6 +1015,8 @@ void UnityAssertGreaterOrLessFloat(const UNITY_FLOAT threshold,
if (!(actual < threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; }
if (!(actual > threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; }
if ((compare & UNITY_EQUAL_TO) && UnityFloatsWithin(threshold * UNITY_FLOAT_PRECISION, threshold, actual)) { failed = 0; }
if (failed)
{
UnityTestResultsFailBegin(lineNumber);
@@ -1022,6 +1024,7 @@ void UnityAssertGreaterOrLessFloat(const UNITY_FLOAT threshold,
UnityPrintFloat(actual);
if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); }
if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); }
if (compare & UNITY_EQUAL_TO) { UnityPrint(UnityStrOrEqual); }
UnityPrintFloat(threshold);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
@@ -1206,6 +1209,8 @@ void UnityAssertGreaterOrLessDouble(const UNITY_DOUBLE threshold,
if (!(actual < threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; }
if (!(actual > threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; }
if ((compare & UNITY_EQUAL_TO) && UnityFloatsWithin(threshold * UNITY_DOUBLE_PRECISION, threshold, actual)) { failed = 0; }
if (failed)
{
UnityTestResultsFailBegin(lineNumber);
@@ -1213,6 +1218,7 @@ void UnityAssertGreaterOrLessDouble(const UNITY_DOUBLE threshold,
UnityPrintFloat(actual);
if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); }
if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); }
if (compare & UNITY_EQUAL_TO) { UnityPrint(UnityStrOrEqual); }
UnityPrintFloat(threshold);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;