Statistiques
| Révision :

root / pobysoC-4.0 / src / test-pobyso-new-monomial.c @ 134

Historique | Voir | Annoter | Télécharger (7,06 ko)

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