MCPcopy Index your code
hub / github.com/DaveGamble/cJSON / UnityAssertFloatSpecial

Function UnityAssertFloatSpecial

tests/unity/src/unity.c:773–830  ·  view source on GitHub ↗

-----------------------------------------------*/

Source from the content-addressed store, hash-verified

771
772/*-----------------------------------------------*/
773void UnityAssertFloatSpecial(const UNITY_FLOAT actual,
774 const char* msg,
775 const UNITY_LINE_TYPE lineNumber,
776 const UNITY_FLOAT_TRAIT_T style)
777{
778 const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet};
779 UNITY_INT should_be_trait = ((UNITY_INT)style & 1);
780 UNITY_INT is_trait = !should_be_trait;
781 UNITY_INT trait_index = (UNITY_INT)(style >> 1);
782
783 RETURN_IF_FAIL_OR_IGNORE;
784
785 switch (style)
786 {
787 case UNITY_FLOAT_IS_INF:
788 case UNITY_FLOAT_IS_NOT_INF:
789 is_trait = isinf(actual) && (actual > 0);
790 break;
791 case UNITY_FLOAT_IS_NEG_INF:
792 case UNITY_FLOAT_IS_NOT_NEG_INF:
793 is_trait = isinf(actual) && (actual < 0);
794 break;
795
796 case UNITY_FLOAT_IS_NAN:
797 case UNITY_FLOAT_IS_NOT_NAN:
798 is_trait = isnan(actual) ? 1 : 0;
799 break;
800
801 case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
802 case UNITY_FLOAT_IS_NOT_DET:
803 is_trait = !isinf(actual) && !isnan(actual);
804 break;
805
806 default:
807 trait_index = 0;
808 trait_names[0] = UnityStrInvalidFloatTrait;
809 break;
810 }
811
812 if (is_trait != should_be_trait)
813 {
814 UnityTestResultsFailBegin(lineNumber);
815 UnityPrint(UnityStrExpected);
816 if (!should_be_trait)
817 UnityPrint(UnityStrNot);
818 UnityPrint(trait_names[trait_index]);
819 UnityPrint(UnityStrWas);
820#ifndef UNITY_EXCLUDE_FLOAT_PRINT
821 UnityPrintFloat((UNITY_DOUBLE)actual);
822#else
823 if (should_be_trait)
824 UnityPrint(UnityStrNot);
825 UnityPrint(trait_names[trait_index]);
826#endif
827 UnityAddMsgIfSpecified(msg);
828 UNITY_FAIL_AND_BAIL;
829 }
830}

Callers

nothing calls this directly

Calls 4

UnityPrintFunction · 0.85
UnityPrintFloatFunction · 0.85
UnityAddMsgIfSpecifiedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…