mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-30 03:34:27 +01:00
Merge pull request #241 from jsalling/cleanup/float-testing
Cleanup floating point print testing, update docs
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* Unity Configuration
|
/* Unity Configuration
|
||||||
* As of May 11th, 2016 at ThrowTheSwitch/Unity commit 837c529
|
* As of May 11th, 2016 at ThrowTheSwitch/Unity commit 837c529
|
||||||
* Update: August 25th, 2016
|
* Update: December 29th, 2016
|
||||||
* See Also: Unity/docs/UnityConfigurationGuide.pdf
|
* See Also: Unity/docs/UnityConfigurationGuide.pdf
|
||||||
*
|
*
|
||||||
* Unity is designed to run on almost anything that is targeted by a C compiler.
|
* Unity is designed to run on almost anything that is targeted by a C compiler.
|
||||||
@@ -37,11 +37,6 @@
|
|||||||
#ifndef UNITY_CONFIG_H
|
#ifndef UNITY_CONFIG_H
|
||||||
#define UNITY_CONFIG_H
|
#define UNITY_CONFIG_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ************************* AUTOMATIC INTEGER TYPES ***************************
|
/* ************************* AUTOMATIC INTEGER TYPES ***************************
|
||||||
* C's concept of an integer varies from target to target. The C Standard has
|
* C's concept of an integer varies from target to target. The C Standard has
|
||||||
* rules about the `int` matching the register size of the target
|
* rules about the `int` matching the register size of the target
|
||||||
@@ -122,10 +117,9 @@ extern "C"
|
|||||||
|
|
||||||
/* By default, Unity guesses that you will want single precision floating point
|
/* By default, Unity guesses that you will want single precision floating point
|
||||||
* support, but not double precision. It's easy to change either of these using
|
* support, but not double precision. It's easy to change either of these using
|
||||||
* the include and exclude options here. You may include neither, either, or
|
* the include and exclude options here. You may include neither, just float,
|
||||||
* both, as suits your needs.
|
* or both, as suits your needs.
|
||||||
*/
|
*/
|
||||||
/* #define UNITY_INCLUDE_FLOAT */
|
|
||||||
/* #define UNITY_EXCLUDE_FLOAT */
|
/* #define UNITY_EXCLUDE_FLOAT */
|
||||||
/* #define UNITY_INCLUDE_DOUBLE */
|
/* #define UNITY_INCLUDE_DOUBLE */
|
||||||
/* #define UNITY_EXCLUDE_DOUBLE */
|
/* #define UNITY_EXCLUDE_DOUBLE */
|
||||||
@@ -137,18 +131,15 @@ extern "C"
|
|||||||
/* Unity aims for as small of a footprint as possible and avoids most standard
|
/* Unity aims for as small of a footprint as possible and avoids most standard
|
||||||
* library calls (some embedded platforms don't have a standard library!).
|
* library calls (some embedded platforms don't have a standard library!).
|
||||||
* Because of this, its routines for printing integer values are minimalist and
|
* Because of this, its routines for printing integer values are minimalist and
|
||||||
* hand-coded. To keep Unity universal, though, we chose to _not_ develop our
|
* hand-coded. To keep Unity universal, though, we eventually chose to develop
|
||||||
* own floating point print routines. Instead, the display of floating point
|
* our own floating point print routines. Still, the display of floating point
|
||||||
* values during a failure are optional. By default, Unity will not print the
|
* values during a failure are optional. By default, Unity will print the
|
||||||
* actual results of floating point assertion failure. So a failed assertion
|
* actual results of floating point assertion failures. So a failed assertion
|
||||||
* will produce a message like `"Values Not Within Delta"`. If you would like
|
* will produce a message like "Expected 4.0 Was 4.25". If you would like less
|
||||||
* verbose failure messages for floating point assertions, use these options to
|
* verbose failure messages for floating point assertions, use this option to
|
||||||
* give more explicit failure messages (e.g. `"Expected 4.56 Was 4.68"`). Note
|
* give a failure message `"Values Not Within Delta"` and trim the binary size.
|
||||||
* that this feature requires the use of `sprintf` so might not be desirable in
|
|
||||||
* all cases.
|
|
||||||
*/
|
*/
|
||||||
/* #define UNITY_FLOAT_VERBOSE */
|
/* #define UNITY_EXCLUDE_FLOAT_PRINT */
|
||||||
/* #define UNITY_DOUBLE_VERBOSE */
|
|
||||||
|
|
||||||
/* If enabled, Unity assumes you want your `FLOAT` asserts to compare standard C
|
/* If enabled, Unity assumes you want your `FLOAT` asserts to compare standard C
|
||||||
* floats. If your compiler supports a specialty floating point type, you can
|
* floats. If your compiler supports a specialty floating point type, you can
|
||||||
@@ -211,8 +202,8 @@ extern "C"
|
|||||||
* serial `RS232_putc()` function you wrote like thus:
|
* serial `RS232_putc()` function you wrote like thus:
|
||||||
*/
|
*/
|
||||||
/* #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) */
|
/* #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) */
|
||||||
/* #define UNITY_OUTPUT_FLUSH() RS232_config(115200,1,8,0) */
|
/* #define UNITY_OUTPUT_FLUSH() RS232_flush() */
|
||||||
/* #define UNITY_OUTPUT_START() RS232_flush() */
|
/* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */
|
||||||
/* #define UNITY_OUTPUT_COMPLETE() RS232_close() */
|
/* #define UNITY_OUTPUT_COMPLETE() RS232_close() */
|
||||||
|
|
||||||
/* For some targets, Unity can make the otherwise required `setUp()` and
|
/* For some targets, Unity can make the otherwise required `setUp()` and
|
||||||
@@ -232,6 +223,7 @@ extern "C"
|
|||||||
*/
|
*/
|
||||||
/* #define UNITY_SUPPORT_WEAK weak */
|
/* #define UNITY_SUPPORT_WEAK weak */
|
||||||
/* #define UNITY_SUPPORT_WEAK __attribute__((weak)) */
|
/* #define UNITY_SUPPORT_WEAK __attribute__((weak)) */
|
||||||
|
/* #define UNITY_NO_WEAK */
|
||||||
|
|
||||||
/* Some compilers require a custom attribute to be assigned to pointers, like
|
/* Some compilers require a custom attribute to be assigned to pointers, like
|
||||||
* `near` or `far`. In these cases, you can give Unity a safe default for these
|
* `near` or `far`. In these cases, you can give Unity a safe default for these
|
||||||
@@ -242,8 +234,4 @@ extern "C"
|
|||||||
/* #define UNITY_PTR_ATTRIBUTE __attribute__((far)) */
|
/* #define UNITY_PTR_ATTRIBUTE __attribute__((far)) */
|
||||||
/* #define UNITY_PTR_ATTRIBUTE near */
|
/* #define UNITY_PTR_ATTRIBUTE near */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* extern "C" */
|
|
||||||
|
|
||||||
#endif /* UNITY_CONFIG_H */
|
#endif /* UNITY_CONFIG_H */
|
||||||
|
|||||||
@@ -642,6 +642,7 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------*/
|
/*-----------------------------------------------*/
|
||||||
|
#ifndef UNITY_EXCLUDE_FLOAT
|
||||||
/* Wrap this define in a function with variable types as float or double */
|
/* Wrap this define in a function with variable types as float or double */
|
||||||
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
|
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
|
||||||
if (isinf(expected) && isinf(actual) && (isneg(expected) == isneg(actual))) return 1; \
|
if (isinf(expected) && isinf(actual) && (isneg(expected) == isneg(actual))) return 1; \
|
||||||
@@ -670,7 +671,6 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
|
|||||||
UnityPrint(UnityStrDelta)
|
UnityPrint(UnityStrDelta)
|
||||||
#endif /* UNITY_EXCLUDE_FLOAT_PRINT */
|
#endif /* UNITY_EXCLUDE_FLOAT_PRINT */
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT
|
|
||||||
static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual)
|
static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual)
|
||||||
{
|
{
|
||||||
UNITY_FLOAT diff;
|
UNITY_FLOAT diff;
|
||||||
|
|||||||
@@ -164,16 +164,15 @@
|
|||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
|
||||||
/* No Floating Point Support */
|
/* No Floating Point Support */
|
||||||
#undef UNITY_INCLUDE_FLOAT
|
#ifndef UNITY_EXCLUDE_DOUBLE
|
||||||
#undef UNITY_FLOAT_PRECISION
|
#define UNITY_EXCLUDE_DOUBLE /* Remove double when excluding float support */
|
||||||
#undef UNITY_FLOAT_TYPE
|
#endif
|
||||||
|
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
||||||
|
#define UNITY_EXCLUDE_FLOAT_PRINT
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifndef UNITY_INCLUDE_FLOAT
|
|
||||||
#define UNITY_INCLUDE_FLOAT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Floating Point Support */
|
/* Floating Point Support */
|
||||||
#ifndef UNITY_FLOAT_PRECISION
|
#ifndef UNITY_FLOAT_PRECISION
|
||||||
#define UNITY_FLOAT_PRECISION (0.00001f)
|
#define UNITY_FLOAT_PRECISION (0.00001f)
|
||||||
@@ -208,29 +207,20 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
|
|||||||
* Double Float Support
|
* Double Float Support
|
||||||
*-------------------------------------------------------*/
|
*-------------------------------------------------------*/
|
||||||
|
|
||||||
/* unlike FLOAT, we DON'T include by default */
|
/* unlike float, we DON'T include by default */
|
||||||
#ifndef UNITY_EXCLUDE_DOUBLE
|
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(UNITY_INCLUDE_DOUBLE)
|
||||||
#ifndef UNITY_INCLUDE_DOUBLE
|
|
||||||
#define UNITY_EXCLUDE_DOUBLE
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef UNITY_EXCLUDE_DOUBLE
|
|
||||||
|
|
||||||
/* No Floating Point Support */
|
/* No Floating Point Support */
|
||||||
#undef UNITY_DOUBLE_PRECISION
|
#ifndef UNITY_EXCLUDE_DOUBLE
|
||||||
#undef UNITY_DOUBLE_TYPE
|
#define UNITY_EXCLUDE_DOUBLE
|
||||||
|
#else
|
||||||
#ifdef UNITY_INCLUDE_DOUBLE
|
|
||||||
#undef UNITY_INCLUDE_DOUBLE
|
#undef UNITY_INCLUDE_DOUBLE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifndef UNITY_EXCLUDE_FLOAT
|
||||||
#define UNITY_EXCLUDE_FLOAT_PRINT
|
#ifndef UNITY_DOUBLE_TYPE
|
||||||
#else
|
#define UNITY_DOUBLE_TYPE double
|
||||||
#ifndef UNITY_DOUBLE_TYPE
|
#endif
|
||||||
#define UNITY_DOUBLE_TYPE double
|
|
||||||
#endif
|
|
||||||
typedef UNITY_FLOAT UNITY_DOUBLE;
|
typedef UNITY_FLOAT UNITY_DOUBLE;
|
||||||
/* For parameter in UnityPrintFloat(UNITY_DOUBLE), which aliases to double or float */
|
/* For parameter in UnityPrintFloat(UNITY_DOUBLE), which aliases to double or float */
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3289,7 +3289,7 @@ void testFloatPrinting(void)
|
|||||||
|
|
||||||
void testFloatPrintingRoundTiesToEven(void)
|
void testFloatPrintingRoundTiesToEven(void)
|
||||||
{
|
{
|
||||||
#if defined(UNITY_EXCLUDE_FLOAT) || !defined(USING_OUTPUT_SPY)
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY)
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
||||||
@@ -3304,7 +3304,7 @@ void testFloatPrintingRoundTiesToEven(void)
|
|||||||
|
|
||||||
void testFloatPrintingInfinityAndNaN(void)
|
void testFloatPrintingInfinityAndNaN(void)
|
||||||
{
|
{
|
||||||
#if defined(UNITY_EXCLUDE_FLOAT) || !defined(USING_OUTPUT_SPY)
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY)
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.0f / f_zero);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.0f / f_zero);
|
||||||
@@ -3934,7 +3934,7 @@ void testNotEqualDoubleArraysLengthZero(void)
|
|||||||
|
|
||||||
void testDoublePrinting(void)
|
void testDoublePrinting(void)
|
||||||
{
|
{
|
||||||
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.10046949999999999);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.10046949999999999);
|
||||||
@@ -3956,7 +3956,7 @@ void testDoublePrinting(void)
|
|||||||
|
|
||||||
void testDoublePrintingRoundTiesToEven(void)
|
void testDoublePrintingRoundTiesToEven(void)
|
||||||
{
|
{
|
||||||
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
||||||
@@ -3971,7 +3971,7 @@ void testDoublePrintingRoundTiesToEven(void)
|
|||||||
|
|
||||||
void testDoublePrintingInfinityAndNaN(void)
|
void testDoublePrintingInfinityAndNaN(void)
|
||||||
{
|
{
|
||||||
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.0 / d_zero);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.0 / d_zero);
|
||||||
|
|||||||
Reference in New Issue
Block a user