summaryrefslogtreecommitdiffstats
path: root/lib/test.c
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-08-09 15:02:21 +0400
committerEthan Werner <mail@ethanwerner.com>2026-08-09 15:02:21 +0400
commit3d92926a902017e7cf1f5738e99ff62da596ce12 (patch)
tree2b55422c26a48759d56fa91f06df24449e9dfa88 /lib/test.c
parent07e18043145f3d91c8ea7ec3ad41b3c905585277 (diff)
refactormain
Diffstat (limited to 'lib/test.c')
-rwxr-xr-xlib/test.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/test.c b/lib/test.c
index 56c47eb..d022f6e 100755
--- a/lib/test.c
+++ b/lib/test.c
@@ -33,42 +33,55 @@ void ts_test_all( void )
}
bool ts_test(
- void ( *ts_function )(
- fp_t * const *y,
- fp_t const * const *x,
- uint_t n,
- ts_constant_t const *c
+ int ( *ts_function )(
+ fp_t * const *y,
+ uint_t y_n,
+ fp_t const * const *x,
+ uint_t x_n,
+ uint_t n,
+ ts_constant_t const *c
),
- uint_t ( *ts_offset )(
- 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 )
-{
+{
+ if ( !ts_function || !ts_offset || !m || !e || !x ) return false;
+
uint_t offset = ts_offset( c );
- uint_t y_n = n - offset;
+ if ( offset >= n ) return false;
+ uint_t y_len = n - offset;
bool result = true;
-
- fp_t *y[m->y];
- for( uint_t i = 0; i < m->y; i++ )
+ fp_t *y[m->n_outputs];
+
+ for( uint_t i = 0; i < m->n_outputs; i++ )
{
- fp_t *tmp = malloc( y_n * sizeof( fp_t ) );
+ fp_t *tmp = calloc( y_len, sizeof( fp_t ) );
+ if ( !tmp )
+ {
+ for ( uint_t j = 0; j < i; j++ ) free( y[j] );
+ return false;
+ }
y[i] = tmp;
}
- ts_function( y, x, n, c );
+ if ( ts_function( y, m->n_outputs, x, m->n_inputs, n, c ) != 0 )
+ {
+ for ( uint_t i = 0; i < m->n_outputs; i++ ) free( y[i] );
+ return false;
+ }
- for( uint_t i = 0; i < m->y; ++i )
+ for( uint_t i = 0; i < m->n_outputs; ++i )
{
- for( uint_t j = 0; j < y_n; ++j )
+ for( uint_t j = 0; j < y_len; ++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 );
- }
+ result &= _ts_is_approximate( y[i][j], e[i][j], TS_TEST_EPSILON );
+ }
free( y[i] );
}