summaryrefslogtreecommitdiffstats
path: root/lib/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/test.c')
-rwxr-xr-xlib/test.c77
1 files changed, 77 insertions, 0 deletions
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 <assert.h>
+#include <math.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#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