Statistiques
| Révision :

root / pobysoC-4.0 / src / test-pobyso-constant-expression.c @ 133

Historique | Voir | Annoter | Télécharger (3,29 ko)

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