root / pobysoC-4.0 / src / test-pobyso-constant-expression.c @ 137
Historique | Voir | Annoter | Télécharger (3,48 ko)
1 |
/** @file test-pobyso-constant-expression.c
|
---|---|
2 |
* Name & purpose
|
3 |
*
|
4 |
* @author
|
5 |
* @date
|
6 |
*
|
7 |
* @details Verbosity manipulation are performed to make sur that verbosity
|
8 |
* suppression is correctly managed in pobyso_is_constant_expression()
|
9 |
* function.
|
10 |
*/
|
11 |
/******************************************************************************/
|
12 |
/* Headers, applying the "particular to general" convention.*/
|
13 |
|
14 |
#include "pobyso.h" |
15 |
|
16 |
/* includes of local headers */
|
17 |
|
18 |
/* includes of project headers */
|
19 |
|
20 |
/* includes of system headers */
|
21 |
|
22 |
/* Other declarations */
|
23 |
|
24 |
/* Internal prototypes */
|
25 |
|
26 |
/* Types, constants and macros definitions */
|
27 |
|
28 |
/* Global variables */
|
29 |
|
30 |
/* Functions */
|
31 |
|
32 |
int
|
33 |
main(int argc, char** argv) |
34 |
{ |
35 |
pobyso_func_exp_t func_exp = NULL;
|
36 |
int verbosity = 0; |
37 |
sollya_obj_t on = NULL;
|
38 |
sollya_obj_t off = NULL;
|
39 |
|
40 |
sollya_lib_init(); |
41 |
|
42 |
pobyso_set_canonical_on(); |
43 |
off = sollya_lib_off(); |
44 |
on = sollya_lib_on(); |
45 |
|
46 |
fprintf(stdout, "NULL argument:\n");
|
47 |
if (! pobyso_is_constant_expression(func_exp))
|
48 |
{ |
49 |
fprintf(stdout, "OK.\n");
|
50 |
} |
51 |
else
|
52 |
{ |
53 |
fprintf(stdout, "Error for NULL argument.\n");
|
54 |
return 1; |
55 |
} |
56 |
|
57 |
fprintf(stdout, "Argument : 1\n");
|
58 |
func_exp = pobyso_parse_string("1");
|
59 |
if (pobyso_is_constant_expression(func_exp))
|
60 |
{ |
61 |
pobyso_autoprint(func_exp); |
62 |
fprintf(stdout, "OK.\n");
|
63 |
sollya_lib_clear_obj(func_exp); |
64 |
} |
65 |
else
|
66 |
{ |
67 |
fprintf(stdout, "Error for \"1\".\n");
|
68 |
return 1; |
69 |
} |
70 |
verbosity = pobyso_set_verbosity_off(); |
71 |
func_exp = pobyso_parse_string("1.1");
|
72 |
pobyso_set_verbosity_to(verbosity); |
73 |
if (pobyso_is_constant_expression(func_exp))
|
74 |
{ |
75 |
pobyso_autoprint(func_exp); |
76 |
fprintf(stdout, "OK.\n");
|
77 |
sollya_lib_clear_obj(func_exp); |
78 |
} |
79 |
else
|
80 |
{ |
81 |
fprintf(stdout, "Error for \"1.1\".\n");
|
82 |
return 1; |
83 |
} |
84 |
|
85 |
func_exp = pobyso_parse_string("1/2");
|
86 |
if (pobyso_is_constant_expression(func_exp))
|
87 |
{ |
88 |
pobyso_set_verbosity_off(); |
89 |
pobyso_autoprint(func_exp); |
90 |
fprintf(stdout, "OK for \"1/2\".\n");
|
91 |
sollya_lib_clear_obj(func_exp); |
92 |
} |
93 |
else
|
94 |
{ |
95 |
fprintf(stdout, "Error for \"1/2\".\n");
|
96 |
return 1; |
97 |
} |
98 |
|
99 |
verbosity = pobyso_set_verbosity_off(); |
100 |
sollya_lib_set_roundingwarnings(off); |
101 |
func_exp = sollya_lib_pi(); |
102 |
pobyso_set_verbosity_to(verbosity); |
103 |
sollya_lib_set_roundingwarnings(on); |
104 |
if (pobyso_is_constant_expression(func_exp))
|
105 |
{ |
106 |
pobyso_autoprint(func_exp); |
107 |
fprintf(stdout,"OK for pi.\n");
|
108 |
sollya_lib_clear_obj(func_exp); |
109 |
} |
110 |
else
|
111 |
{ |
112 |
fprintf(stdout, "Error for \"pi\".\n");
|
113 |
return 1; |
114 |
} |
115 |
|
116 |
func_exp = pobyso_parse_string("x^2");
|
117 |
if (! pobyso_is_constant_expression(func_exp))
|
118 |
{ |
119 |
fprintf(stdout, "Non constant expression \"x^2\": OK\n");
|
120 |
} |
121 |
else
|
122 |
{ |
123 |
fprintf(stdout, "Error for \"x^2\".\n");
|
124 |
return 1; |
125 |
} |
126 |
|
127 |
func_exp = pobyso_parse_string("cos(x)");
|
128 |
if (! pobyso_is_constant_expression(func_exp))
|
129 |
{ |
130 |
pobyso_autoprint(func_exp); |
131 |
fprintf(stdout, "OK for non constant expression \"cos(x)\".\n");
|
132 |
sollya_lib_clear_obj(func_exp); |
133 |
} |
134 |
else
|
135 |
{ |
136 |
fprintf(stdout, "Error for \"cos(x)\".\n");
|
137 |
return 1; |
138 |
} |
139 |
|
140 |
verbosity = pobyso_set_verbosity_off(); |
141 |
func_exp = pobyso_parse_string("cos(pi)");
|
142 |
pobyso_set_verbosity_to(verbosity); |
143 |
if (pobyso_is_constant_expression(func_exp))
|
144 |
{ |
145 |
pobyso_set_verbosity_off(); |
146 |
pobyso_autoprint(func_exp); |
147 |
fprintf(stdout, "OK for \"cos(pi)\".\n");
|
148 |
sollya_lib_clear_obj(func_exp); |
149 |
} |
150 |
else
|
151 |
{ |
152 |
fprintf(stdout, "Error for \"cos(pi)\".\n");
|
153 |
return 1; |
154 |
} |
155 |
/* */
|
156 |
|
157 |
sollya_lib_close(); |
158 |
return 0; |
159 |
} /* End main */
|