ZTEST: Add optional float/double comparison support #13569
Labels
area: Test Framework
Issues related not to a particular test, but to the framework instead
Enhancement
Changes/Updates/Additions to existing features
Currently the
zassert_*
functions in the ztest API are based on integer values, which can be accurately compared (1==1
, etc.).There are no options for single or double precision floating point value comparisons, which are error-prone to compare againist fixed operands (
x==0.5f
), particularly with single-precision values.When
CONFIG_FLOAT
is enabled, options should be included to compare single and double precision values for equality within a specific margin.In previous projects, I've implemented the following helper functions to work with floating point values in unit tests ...
... which allows tests like the following code, with control over the degree of prevision involved in the comparison:
I understand the allergy to float in an embedded context, but if
CONFIG_FLOAT
has been set toy
and is being used in the application or library, shouldn't the option be available to test said floating point values in both single and double-precision widths, using 'safer' value comparisons?I can continue to use my own code to test these, but it seems reasonable to at least consider adding these helpers to ztest and ztest_assert.h with an appropriate check for
CONFIG_FLOAT
?The text was updated successfully, but these errors were encountered: