MCPcopy Create free account
hub / github.com/DaveGamble/cJSON / printFloatValue

Function printFloatValue

tests/unity/test/tests/testunity.c:4525–4554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4523
4524#if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY)
4525static void printFloatValue(float f)
4526{
4527 char expected[18];
4528 char expected_lower[18];
4529 char expected_higher[18];
4530
4531 startPutcharSpy();
4532
4533 UnityPrintFloat(f);
4534
4535 sprintf(expected, "%.6g", f);
4536
4537 /* We print all NaN's as "nan", not "-nan" */
4538 if(strcmp(expected, "-nan") == 0) strcpy(expected, "nan");
4539
4540 /* Allow for rounding differences in last digit */
4541 double lower = (double)f * 0.9999995;
4542 double higher = (double)f * 1.0000005;
4543
4544 if (isfinite(lower)) sprintf(expected_lower, "%.6g", lower); else strcpy(expected_lower, expected);
4545 if (isfinite(higher)) sprintf(expected_higher, "%.6g", higher); else strcpy(expected_higher, expected);
4546
4547 if (strcmp(expected, getBufferPutcharSpy()) != 0 &&
4548 strcmp(expected_lower, getBufferPutcharSpy()) != 0 &&
4549 strcmp(expected_higher, getBufferPutcharSpy()) != 0)
4550 {
4551 /* Fail with diagnostic printing */
4552 TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f);
4553 }
4554}
4555#endif
4556
4557void testFloatPrintingRandomSamples(void)

Callers 1

Calls 3

startPutcharSpyFunction · 0.85
UnityPrintFloatFunction · 0.85
getBufferPutcharSpyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…