mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 01:49:53 +00:00
tests: Use fuzzy comparison in test-suite
Using exact comparison ("a == b") when comparing expected with computed test data fails the test-suite on many architectures (including, but not limited to armhf and arm64). Instead, use epsilon(for now, FLT_EPSILON and DBL_EPSILON) to compare floating point numbers for equality. Closes: https://github.com/libsndfile/libsndfile/issues/866 Signed-off-by: IOhannes m zmölnig <zmoelnig@iem.at>
This commit is contained in:
parent
36216ba105
commit
cefd7b59df
@ -193,6 +193,7 @@ sf_count_t file_length_fd (int fd) ;
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@ -215,6 +216,28 @@ sf_count_t file_length_fd (int fd) ;
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Compare for equality, with epsilon
|
||||
*/
|
||||
static inline int
|
||||
equals_short (const short a, const short b)
|
||||
{ return (a == b);
|
||||
} /* equals_short */
|
||||
static inline int
|
||||
equals_int (const int a, const int b)
|
||||
{ return (a == b);
|
||||
} /* equals_int */
|
||||
static inline int
|
||||
equals_float (const float a, const float b)
|
||||
{ return (fabsf(a - b) <= FLT_EPSILON);
|
||||
} /* equals_float */
|
||||
static inline int
|
||||
equals_double (const double a, const double b)
|
||||
{ return (fabs(a - b) <= DBL_EPSILON);
|
||||
} /* equals_double */
|
||||
|
||||
|
||||
[+ FOR float_type +]
|
||||
void
|
||||
gen_windowed_sine_[+ (get "name") +] ([+ (get "name") +] *data, int len, double maximum)
|
||||
@ -752,8 +775,8 @@ compare_[+ (get "io_element") +]_or_die (const [+ (get "io_element") +] *expecte
|
||||
unsigned k ;
|
||||
|
||||
for (k = 0 ; k < count ; k++)
|
||||
if (expected [k] != actual [k])
|
||||
{ printf ("\n\nLine %d : Error at index %d, got " [+ (get "format_str") +] ", should be " [+ (get "format_str") +] ".\n\n", line_num, k, actual [k], expected [k]) ;
|
||||
if (!equals_[+ (get "io_element") +](expected [k], actual [k]))
|
||||
{ printf ("\n\nLine %d : Error at index %d, got " [+ (get "format_str") +] ", should be " [+ (get "format_str") +] "(delta=" [+ (get "format_str") +] " ).\n\n", line_num, k, actual [k], expected [k], actual [k] - expected [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user