root / pobysoC-4.0 / src / test-pobyso-new-monomial.c @ 143
Historique | Voir | Annoter | Télécharger (7,06 ko)
1 |
/** @file test-pobyso-new-monomial.c
|
---|---|
2 |
* Name & purpose
|
3 |
*
|
4 |
* @author S.T.
|
5 |
* @date 2014-11-10
|
6 |
*
|
7 |
* @details
|
8 |
*/
|
9 |
/******************************************************************************/
|
10 |
/* Headers, applying the "particular to general" convention.*/
|
11 |
|
12 |
#include "pobyso.h" |
13 |
|
14 |
/* includes of local headers */
|
15 |
|
16 |
/* includes of project headers */
|
17 |
|
18 |
/* includes of system headers */
|
19 |
|
20 |
/* Other declarations */
|
21 |
|
22 |
/* Internal prototypes */
|
23 |
|
24 |
/* Types, constants and macros definitions */
|
25 |
|
26 |
/* Global variables */
|
27 |
|
28 |
/* Functions */
|
29 |
|
30 |
int
|
31 |
main(int argc, char** argv) |
32 |
{ |
33 |
pobyso_func_exp_t func_exp = NULL;
|
34 |
pobyso_func_exp_t monomial = NULL;
|
35 |
int verbosity = 0; |
36 |
long degree = 4; |
37 |
long negativeDegree = -1; |
38 |
long zeroDegree = 0; |
39 |
|
40 |
sollya_lib_init(); |
41 |
|
42 |
pobyso_set_canonical_on(); |
43 |
verbosity = pobyso_get_verbosity(); |
44 |
|
45 |
/* NULL coefficient. */
|
46 |
fprintf(stdout, "\nNULL coefficient:\n");
|
47 |
if (pobyso_new_monomial(NULL, degree) == NULL) |
48 |
{ |
49 |
fprintf(stdout, "OK for NULL coefficient and degree %ld.\n", degree);
|
50 |
} |
51 |
else
|
52 |
{ |
53 |
fprintf(stdout, "Error for NULL coefficient and degree %ld.\n", degree);
|
54 |
return 1; |
55 |
} |
56 |
fprintf(stdout, "\n");
|
57 |
|
58 |
/* Integer constant argument "1". */
|
59 |
fprintf(stdout, "Coefficient \"1\":\n");
|
60 |
func_exp = pobyso_parse_string("1");
|
61 |
monomial = pobyso_new_monomial(func_exp, degree); |
62 |
if (monomial != NULL) |
63 |
{ |
64 |
pobyso_autoprint(monomial); |
65 |
fprintf(stdout, "OK for coefficient \"1\" and degree %ld.\n", degree);
|
66 |
sollya_lib_clear_obj(func_exp); |
67 |
sollya_lib_clear_obj(monomial); |
68 |
} |
69 |
else
|
70 |
{ |
71 |
fprintf(stdout, "Error for \"1\" and degree %ld.\n", degree);
|
72 |
sollya_lib_clear_obj(func_exp); |
73 |
return 1; |
74 |
} |
75 |
fprintf(stdout, "\n");
|
76 |
|
77 |
/* Double coefficient. */
|
78 |
fprintf(stdout, "Coefficient \"1.1\":\n");
|
79 |
pobyso_set_verbosity_off(); |
80 |
func_exp = pobyso_parse_string("1.1");
|
81 |
pobyso_set_verbosity_to(verbosity); |
82 |
monomial = pobyso_new_monomial(func_exp, degree); |
83 |
if (monomial != NULL) |
84 |
{ |
85 |
pobyso_autoprint(monomial); |
86 |
fprintf(stdout, "OK.\n");
|
87 |
sollya_lib_clear_obj(func_exp); |
88 |
sollya_lib_clear_obj(monomial); |
89 |
} |
90 |
else
|
91 |
{ |
92 |
fprintf(stdout, "Error for \"1.1\" and degree %ld.\n", degree);
|
93 |
sollya_lib_clear_obj(func_exp); |
94 |
return 1; |
95 |
} |
96 |
fprintf(stdout, "\n");
|
97 |
|
98 |
/* Rational coefficient. */
|
99 |
fprintf(stdout, "Coefficient \"1/2\":\n");
|
100 |
func_exp = pobyso_parse_string("1/2");
|
101 |
monomial = pobyso_new_monomial(func_exp, degree); |
102 |
if (monomial != NULL) |
103 |
{ |
104 |
pobyso_autoprint(monomial); |
105 |
fprintf(stdout, "OK for coefficient \"1/2\" and degree %ld.\n", degree);
|
106 |
sollya_lib_clear_obj(func_exp); |
107 |
sollya_lib_clear_obj(monomial); |
108 |
} |
109 |
else
|
110 |
{ |
111 |
fprintf(stdout, "Error for coefficient \"1/2\" and degree %ld.\n", degree);
|
112 |
sollya_lib_clear_obj(func_exp); |
113 |
return 1; |
114 |
} |
115 |
fprintf(stdout, "\n");
|
116 |
|
117 |
/* Pi constant argument */
|
118 |
fprintf(stdout, "Coefficient pi:\n");
|
119 |
pobyso_set_verbosity_off(); |
120 |
func_exp = sollya_lib_pi(); |
121 |
pobyso_set_verbosity_to(verbosity); |
122 |
monomial = pobyso_new_monomial(func_exp, degree); |
123 |
if (monomial != NULL) |
124 |
{ |
125 |
pobyso_set_verbosity_off(); |
126 |
pobyso_autoprint(monomial); |
127 |
pobyso_set_verbosity_to(verbosity); |
128 |
fprintf(stdout,"OK for coefficient \"pi\" and degree %ld.\n", degree);
|
129 |
sollya_lib_clear_obj(func_exp); |
130 |
sollya_lib_clear_obj(monomial); |
131 |
} |
132 |
else
|
133 |
{ |
134 |
fprintf(stdout, "Error for coefficient \"pi\" and degree %ld.\n", degree);
|
135 |
sollya_lib_clear_obj(func_exp); |
136 |
return 1; |
137 |
} |
138 |
fprintf(stdout, "\n");
|
139 |
|
140 |
/* Non constant functional expression x^2. */
|
141 |
fprintf(stdout,"Coefficient \"x^2\":\n");
|
142 |
func_exp = pobyso_parse_string("x^2");
|
143 |
monomial = pobyso_new_monomial(func_exp, degree); |
144 |
if (monomial == NULL) |
145 |
{ |
146 |
fprintf(stdout, |
147 |
"OK for non-constant expression coefficient \"x^2\" with degree %ld.\n",
|
148 |
degree); |
149 |
sollya_lib_clear_obj(func_exp); |
150 |
} |
151 |
else
|
152 |
{ |
153 |
pobyso_autoprint(monomial); |
154 |
fprintf(stdout, |
155 |
"Error for non-constant expression \"x^2\" with degree %ld.\n",
|
156 |
degree); |
157 |
sollya_lib_clear_obj(func_exp); |
158 |
sollya_lib_clear_obj(monomial); |
159 |
return 1; |
160 |
} |
161 |
fprintf(stdout, "\n");
|
162 |
|
163 |
/* Non-constant functional expression cos(x). */
|
164 |
fprintf(stdout, "Coefficient \"cos(x)\":\n");
|
165 |
func_exp = pobyso_parse_string("cos(x)");
|
166 |
monomial = pobyso_new_monomial(func_exp, degree); |
167 |
if (monomial == NULL) |
168 |
{ |
169 |
pobyso_autoprint(func_exp); |
170 |
fprintf(stdout, |
171 |
"OK for non-constant expression \"cos(x)\" with degree %ld.\n",
|
172 |
degree); |
173 |
sollya_lib_clear_obj(func_exp); |
174 |
} |
175 |
else
|
176 |
{ |
177 |
fprintf(stdout, |
178 |
"Error for coefficient \"cos(x)\" with degree %ld.\n",
|
179 |
degree); |
180 |
sollya_lib_clear_obj(func_exp); |
181 |
sollya_lib_clear_obj(monomial); |
182 |
return 1; |
183 |
} |
184 |
fprintf(stdout, "\n");
|
185 |
|
186 |
/* Constant functional expression cos(pi). */
|
187 |
fprintf(stdout, "Coefficient \"cos(pi)\":\n");
|
188 |
pobyso_set_verbosity_off(); |
189 |
func_exp = pobyso_parse_string("cos(pi)");
|
190 |
pobyso_set_verbosity_to(verbosity); |
191 |
monomial = pobyso_new_monomial(func_exp, degree); |
192 |
if (monomial != NULL) |
193 |
{ |
194 |
pobyso_set_verbosity_off(); |
195 |
pobyso_autoprint(monomial); |
196 |
pobyso_set_verbosity_to(verbosity); |
197 |
fprintf(stdout, "OK for coefficient \"cos(pi)\" and degree %ld.\n", degree);
|
198 |
sollya_lib_clear_obj(func_exp); |
199 |
sollya_lib_clear_obj(monomial); |
200 |
} |
201 |
else
|
202 |
{ |
203 |
fprintf(stdout, |
204 |
"Error for coefficient \"cos(pi)\" and degree %ld.\n",
|
205 |
degree); |
206 |
sollya_lib_clear_obj(func_exp); |
207 |
return 1; |
208 |
} |
209 |
fprintf(stdout, "\n");
|
210 |
|
211 |
/* Constant functional expression cos(pi) but with negative degree. */
|
212 |
fprintf(stdout, "Coefficient \"cos(pi)\" with a negative degree:\n");
|
213 |
pobyso_set_verbosity_off(); |
214 |
func_exp = pobyso_parse_string("cos(pi)");
|
215 |
pobyso_set_verbosity_to(verbosity); |
216 |
monomial = pobyso_new_monomial(func_exp, negativeDegree); |
217 |
if (monomial == NULL) |
218 |
{ |
219 |
fprintf(stdout, "OK for \"cos(pi)\" and degree %ld.\n", negativeDegree);
|
220 |
sollya_lib_clear_obj(func_exp); |
221 |
} |
222 |
else
|
223 |
{ |
224 |
pobyso_set_verbosity_off(); |
225 |
pobyso_autoprint(monomial); |
226 |
pobyso_set_verbosity_to(verbosity); |
227 |
fprintf(stdout, "Error for \"cos(pi)\" and degree %ld.\n", negativeDegree);
|
228 |
sollya_lib_clear_obj(func_exp); |
229 |
sollya_lib_clear_obj(monomial); |
230 |
return 1; |
231 |
} |
232 |
fprintf(stdout, "\n");
|
233 |
|
234 |
/* Constant functional expression cos(pi) but with degree == 0. */
|
235 |
fprintf(stdout, "Coefficient \"cos(pi)\" with a degree == 0:\n");
|
236 |
pobyso_set_verbosity_off(); |
237 |
func_exp = pobyso_parse_string("cos(pi)");
|
238 |
pobyso_set_verbosity_to(verbosity); |
239 |
monomial = pobyso_new_monomial(func_exp, zeroDegree); |
240 |
if (monomial != NULL) |
241 |
{ |
242 |
pobyso_set_verbosity_off(); |
243 |
pobyso_autoprint(monomial); |
244 |
pobyso_set_verbosity_to(verbosity); |
245 |
fprintf(stdout, "OK for \"cos(pi)\" and degree %ld.\n", zeroDegree);
|
246 |
sollya_lib_clear_obj(func_exp); |
247 |
sollya_lib_clear_obj(monomial); |
248 |
} |
249 |
else
|
250 |
{ |
251 |
fprintf(stdout, "Error for \"cos(pi)\" and degree %ld.\n", zeroDegree);
|
252 |
sollya_lib_clear_obj(func_exp); |
253 |
return 1; |
254 |
} |
255 |
fprintf(stdout, "\n");
|
256 |
fprintf(stdout, "Check correctly finished.\n");
|
257 |
fprintf(stdout, "\n");
|
258 |
/* */
|
259 |
|
260 |
sollya_lib_close(); |
261 |
return 0; |
262 |
} /* End main */
|