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