mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-05-21 09:27:53 +08:00
Refactor repeated code to print float expected and actual
Move double tests down in the file
This commit is contained in:
49
src/unity.c
49
src/unity.c
@ -694,6 +694,19 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
|
|||||||
#define UNITY_NAN_CHECK 0
|
#define UNITY_NAN_CHECK 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
||||||
|
#define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \
|
||||||
|
do { \
|
||||||
|
UnityPrint(UnityStrExpected); \
|
||||||
|
UnityPrintFloat(expected); \
|
||||||
|
UnityPrint(UnityStrWas); \
|
||||||
|
UnityPrintFloat(actual); \
|
||||||
|
} while(0)
|
||||||
|
#else
|
||||||
|
#define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \
|
||||||
|
UnityPrint(UnityStrDelta)
|
||||||
|
#endif /* UNITY_EXCLUDE_FLOAT_PRINT */
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT
|
#ifndef UNITY_EXCLUDE_FLOAT
|
||||||
|
|
||||||
static int UnityFloatsWithin(_UF delta, _UF expected, _UF actual)
|
static int UnityFloatsWithin(_UF delta, _UF expected, _UF actual)
|
||||||
@ -729,14 +742,7 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
|
|||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
UnityPrint(UnityStrElement);
|
UnityPrint(UnityStrElement);
|
||||||
UnityPrintNumberUnsigned(num_elements - elements - 1);
|
UnityPrintNumberUnsigned(num_elements - elements - 1);
|
||||||
#ifdef UNITY_FLOAT_VERBOSE
|
UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(*ptr_expected, *ptr_actual);
|
||||||
UnityPrint(UnityStrExpected);
|
|
||||||
UnityPrintFloat(*ptr_expected);
|
|
||||||
UnityPrint(UnityStrWas);
|
|
||||||
UnityPrintFloat(*ptr_actual);
|
|
||||||
#else
|
|
||||||
UnityPrint(UnityStrDelta);
|
|
||||||
#endif
|
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
}
|
}
|
||||||
@ -758,14 +764,7 @@ void UnityAssertFloatsWithin(const _UF delta,
|
|||||||
if (!UnityFloatsWithin(delta, expected, actual))
|
if (!UnityFloatsWithin(delta, expected, actual))
|
||||||
{
|
{
|
||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual);
|
||||||
UnityPrint(UnityStrExpected);
|
|
||||||
UnityPrintFloat(expected);
|
|
||||||
UnityPrint(UnityStrWas);
|
|
||||||
UnityPrintFloat(actual);
|
|
||||||
#else
|
|
||||||
UnityPrint(UnityStrDelta);
|
|
||||||
#endif
|
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
}
|
}
|
||||||
@ -872,14 +871,7 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
|
|||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
UnityPrint(UnityStrElement);
|
UnityPrint(UnityStrElement);
|
||||||
UnityPrintNumberUnsigned(num_elements - elements - 1);
|
UnityPrintNumberUnsigned(num_elements - elements - 1);
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(*ptr_expected, *ptr_actual);
|
||||||
UnityPrint(UnityStrExpected);
|
|
||||||
UnityPrintFloat(*ptr_expected);
|
|
||||||
UnityPrint(UnityStrWas);
|
|
||||||
UnityPrintFloat(*ptr_actual);
|
|
||||||
#else
|
|
||||||
UnityPrint(UnityStrDelta);
|
|
||||||
#endif
|
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
}
|
}
|
||||||
@ -900,14 +892,7 @@ void UnityAssertDoublesWithin(const _UD delta,
|
|||||||
if (!UnityDoublesWithin(delta, expected, actual))
|
if (!UnityDoublesWithin(delta, expected, actual))
|
||||||
{
|
{
|
||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual);
|
||||||
UnityPrint(UnityStrExpected);
|
|
||||||
UnityPrintFloat(expected);
|
|
||||||
UnityPrint(UnityStrWas);
|
|
||||||
UnityPrintFloat(actual);
|
|
||||||
#else
|
|
||||||
UnityPrint(UnityStrDelta);
|
|
||||||
#endif
|
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
}
|
}
|
||||||
|
@ -3313,56 +3313,6 @@ void testFloatPrintingInfinityAndNaN(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testDoublePrinting(void)
|
|
||||||
{
|
|
||||||
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
|
||||||
TEST_IGNORE();
|
|
||||||
#else
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.10046949999999999);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("4294967295.999999", 4294967295.999999);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967295.9999995);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 9999999995.0);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199254740990.0);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("7.0e+100", 7.0e+100);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("3.0e+200", 3.0e+200);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23456789e+300", 9.23456789e+300);
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.10046949999999999);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4294967295.999999", -4294967295.999999);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967295.9999995);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.0e+100", -7.0e+100);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void testDoublePrintingRoundTiesToEven(void)
|
|
||||||
{
|
|
||||||
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
|
||||||
TEST_IGNORE();
|
|
||||||
#else
|
|
||||||
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00000001e+10", 10000000050.0);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199245000000.0);
|
|
||||||
#else /* Default to Round ties to even */
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 10000000050.0);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719924e+15", 9007199245000000.0);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void testDoublePrintingInfinityAndNaN(void)
|
|
||||||
{
|
|
||||||
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
|
||||||
TEST_IGNORE();
|
|
||||||
#else
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.7976931348623157e308*10.0);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.0 / d_zero);
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-Inf", -1.7976931348623157e308*10.0);
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("NaN", -1.7976931348623157e308*10.0 * d_zero);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ==================
|
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ==================
|
||||||
|
|
||||||
void testDoublesWithinDelta(void)
|
void testDoublesWithinDelta(void)
|
||||||
@ -3886,6 +3836,56 @@ void testNotEqualDoubleArraysLengthZero(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testDoublePrinting(void)
|
||||||
|
{
|
||||||
|
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.10046949999999999);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("4294967295.999999", 4294967295.999999);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967295.9999995);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 9999999995.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199254740990.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("7.0e+100", 7.0e+100);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("3.0e+200", 3.0e+200);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23456789e+300", 9.23456789e+300);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.10046949999999999);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4294967295.999999", -4294967295.999999);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967295.9999995);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.0e+100", -7.0e+100);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void testDoublePrintingRoundTiesToEven(void)
|
||||||
|
{
|
||||||
|
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00000001e+10", 10000000050.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199245000000.0);
|
||||||
|
#else /* Default to Round ties to even */
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 10000000050.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719924e+15", 9007199245000000.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void testDoublePrintingInfinityAndNaN(void)
|
||||||
|
{
|
||||||
|
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.7976931348623157e308*10.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.0 / d_zero);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-Inf", -1.7976931348623157e308*10.0);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("NaN", -1.7976931348623157e308*10.0 * d_zero);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DETAIL SUPPORT ==================
|
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DETAIL SUPPORT ==================
|
||||||
|
|
||||||
void testThatDetailsCanBeHandleOneDetail(void)
|
void testThatDetailsCanBeHandleOneDetail(void)
|
||||||
|
Reference in New Issue
Block a user