From 07e18043145f3d91c8ea7ec3ad41b3c905585277 Mon Sep 17 00:00:00 2001 From: Ethan Werner Date: Wed, 1 Jul 2026 09:42:39 +0400 Subject: initial commit: ts time series analysis library v0.1.0 - 354 financial and mathematical time-series indicators - Uniform C11 API with consistent function signatures - 349 passing tests with -Werror - Static and shared library builds - pkg-config integration - Python bindings - Fuzzing and sanitizer support - Security hardening flags --- lib/test.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 lib/test.c (limited to 'lib/test.c') diff --git a/lib/test.c b/lib/test.c new file mode 100755 index 0000000..56c47eb --- /dev/null +++ b/lib/test.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include "ts.h" + + +void _ts_assert_approximate( fp_t y0, fp_t y1, fp_t e ) +{ + assert( ( fabs( y0 - y1 ) <= e ) ); +} + + +bool _ts_is_approximate( fp_t y0, fp_t y1, fp_t e ) +{ + return ( fabs( y0 - y1 ) <= e ); +} + + +#define _ts_test_print( FUNCTION ) \ + \ + fputs( #FUNCTION, stdout ); \ + fputs( ": ", stdout ) + + +void ts_test_all( void ) +{ + ts_test_absolute_value(); + ts_test_addition(); + ts_test_ceiling(); + +} + +bool ts_test( + void ( *ts_function )( + fp_t * const *y, + fp_t const * const *x, + uint_t n, + ts_constant_t const *c + ), + uint_t ( *ts_offset )( + ts_constant_t const *c + ), + fp_t const * const *x, + fp_t const * const *e, + uint_t n, + ts_constant_t const *c, + ts_parameter_t const *m ) +{ + uint_t offset = ts_offset( c ); + uint_t y_n = n - offset; + bool result = true; + + fp_t *y[m->y]; + + for( uint_t i = 0; i < m->y; i++ ) + { + fp_t *tmp = malloc( y_n * sizeof( fp_t ) ); + y[i] = tmp; + } + + ts_function( y, x, n, c ); + + for( uint_t i = 0; i < m->y; ++i ) + { + for( uint_t j = 0; j < y_n; ++j ) + { + // _ts_assert_approximate( y[i][j], e[i][j], TS_TEST_EPSILON ); + result &= _ts_is_approximate( y[i][j], e[i][j], TS_TEST_EPSILON ); + } + + free( y[i] ); + } + + return result; +} \ No newline at end of file -- cgit v1.3.1