1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
}
|