-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
164 lines (131 loc) · 3.49 KB
/
test.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* \file test.c
* Test the quadreg_calc function
*/
/* header of standard C - libraries */
#include <stdio.h>
#include <string.h>
#include <math.h>
/* header of common types */
/* shared common header */
/* header of project specific types */
/* project headers */
/* local header */
#include "poly2reg.h"
/* constant definitions
---------------------------------------------------------------------------*/
#ifndef countof
#define countof( x ) ( sizeof(x)/ sizeof(x[0]) )
#endif
/* local defined data types
---------------------------------------------------------------------------*/
/* list of external used functions, if not in headers
---------------------------------------------------------------------------*/
/* list of global defined functions
---------------------------------------------------------------------------*/
/* list of local defined functions
---------------------------------------------------------------------------*/
int test_1( void );
int test_rosetta( void );
/* external variables
---------------------------------------------------------------------------*/
/* global variables
---------------------------------------------------------------------------*/
/* local defined variables
---------------------------------------------------------------------------*/
#ifdef CONFIG_FILE_ID
static char _fileid[] = "$Id$";
#endif
/***************************************************************************/
/**
* Run the test code.
*/
int main(
int argc, /**< */
char **argv
)
{
int SuccessCnt = 0;
int FailureCnt = 0;
setvbuf(stdout, NULL, _IONBF, 0);
if( test_1() )
{
SuccessCnt++;
}
else
{
FailureCnt++;
}
if( test_rosetta() )
{
SuccessCnt++;
}
else
{
FailureCnt++;
}
printf("Success/Failure: %d/%d\n\n", SuccessCnt, FailureCnt);
return 0;
}
/**
* Test case 1
*/
int test_1( void )
{
float BufX[] = {1, 2, 3, 4, 5, 6, 7 };
float BufY[] = {0.38, 1.15, 2.71, 3.92, 5.93, 8.56, 11.24};
float Coeff[3];
int _Coeff[3];
poly2reg( Coeff, BufX, BufY, countof(BufX) );
_Coeff[0] = Coeff[0] * 10000;
_Coeff[1] = Coeff[1] * 10000;
_Coeff[2] = Coeff[2] * 10000;
#if 0
printf( "Test 1\n"
"a = %.5f/%d\n"
"b = %.5f/%d\n"
"c = %.5f/%d\n\n",
Coeff[0], _Coeff[0],
Coeff[1], _Coeff[1],
Coeff[2], _Coeff[2]
);
#endif
if( (_Coeff[0] == 1964) && (_Coeff[1] == 2364)&& (_Coeff[2] ==-328) )
{
return 1;
}
return 0;
}
/**
* The rosetta code archive presents solutions for a task in many languages.
* It also has a task for polynomial regression.
* This test uses the values and checks if the result is the same.
* http://rosettacode.org/wiki/Polynomial_regression
*/
int test_rosetta( void )
{
float BufX[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
float BufY[] = {1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321};
float Coeff[3];
int _Coeff[3];
poly2reg( Coeff, BufX, BufY, countof(BufX) );
_Coeff[0] = Coeff[0] * 10000;
_Coeff[1] = Coeff[1] * 10000;
_Coeff[2] = Coeff[2] * 10000;
#if 0
printf( "Test Rosetta\n"
"a = %.5f/%d\n"
"b = %.5f/%d\n"
"c = %.5f/%d\n\n",
Coeff[0], _Coeff[0],
Coeff[1], _Coeff[1],
Coeff[2], _Coeff[2]
);
#endif
if( (_Coeff[0] == 30000) && (_Coeff[1] == 20000)&& (_Coeff[2] == 10000) )
{
return 1;
}
return 0;
}
/*______________________________________________________________________EOF_*/