source: git/coeffs/test.cc @ 2e6a06

spielwiese
Last change on this file since 2e6a06 was 2e6a06, checked in by Oleksandr Motsak <motsak@…>, 14 years ago
More tests. Problem: global variables are needed for long_R/C :( New TODOs :)
  • Property mode set to 100644
File size: 6.0 KB
Line 
1#include "config.h"
2
3#include <auxiliary.h>
4
5#include <coeffs.h>
6#include <numbers.h>
7#include <reporter.h>
8#include <omalloc.h>
9
10#include <longrat.h>
11#include <gnumpfl.h>
12#include <gnumpc.h>
13#include <shortfl.h>
14#include <ffields.h>
15#include <modulop.h>
16#include <rmodulon.h>
17#include <rmodulo2m.h>
18#include <rintegers.h>
19
20#include <iostream>
21
22using namespace std;
23
24
25bool Test(const coeffs r)
26{
27  number a = n_Init(666, r);
28   
29  StringSetS("a: ");
30  n_Test(a,r);
31  n_Write(a, r);
32  PrintS(StringAppend("\n"));
33
34  number two = n_Init(2, r);
35 
36  StringSetS("two: ");
37  n_Test(two,r);
38  n_Write(two, r);
39  PrintS(StringAppend("\n"));
40
41  if (getCoeffType(r) == n_GF) //some special test for GF
42  {
43    number z= nfPar (2, r);
44    StringSetS("z: ");
45    n_Test(z,r); n_Write (z,r);
46    PrintS(StringAppend("\n"));
47  }
48 
49  number aa = n_Add(a, a, r);
50
51  StringSetS("aa = a + a: ");
52  n_Test(aa,r); n_Write(aa, r);
53  PrintS(StringAppend("\n"));
54
55 
56  number aa2 = n_Mult(a, two, r);
57
58  StringSetS("aa2 = a * 2: ");
59  n_Test(aa2, r); n_Write(aa2, r);
60  PrintS(StringAppend("\n"));
61
62  number aa1 = n_Mult(two, a, r);
63
64 
65  StringSetS("aa1 = 2 * a: ");
66  n_Test(aa1,r); n_Write(aa1, r);
67  PrintS(StringAppend("\n"));
68
69
70  n_Delete(&a, r);
71  n_Delete(&two, r);
72
73
74  a = n_Sub( aa, aa1, r );
75 
76  StringSetS("a = aa - aa1: ");
77  n_Test(a,r); n_Write(a, r);
78  PrintS(StringAppend("\n"));
79
80  if( !n_IsZero(a, r) )
81    WarnS("ERROR: a != 0 !!!\n");
82
83  n_Delete(&a, r);
84
85
86
87  a = n_Sub( aa, aa2, r );
88
89  StringSetS("a = aa - aa2: ");
90  n_Test(a,r); n_Write(a, r);
91  PrintS(StringAppend("\n"));
92
93  if( !n_IsZero(a, r) )
94    WarnS("ERROR: a != 0 !!!\n");
95
96  n_Delete(&a, r);
97
98
99  a = n_Sub( aa1, aa2, r );
100
101  StringSetS("a = aa1 - aa2: ");
102  n_Test(a,r); n_Write(a, r);
103  PrintS(StringAppend("\n"));
104
105  if( !n_IsZero(a, r) )
106    WarnS("ERROR: a != 0 !!!\n");
107
108  n_Delete(&a, r);
109
110
111 
112  if( !n_Equal(aa, aa1, r) )
113    WarnS("ERROR: aa != aa1  !!!\n");
114
115  if( !n_Equal(aa, aa2, r) )
116    WarnS("ERROR: aa != aa2  !!!\n");
117
118  if( !n_Equal(aa1, aa2, r) )
119    WarnS("ERROR: aa1 != aa2  !!!\n");
120 
121
122 
123
124  n_Delete(&aa, r);
125  n_Delete(&aa1, r);
126  n_Delete(&aa2, r);
127
128  return false;
129}
130
131
132
133namespace
134{
135  static inline ostream& operator<< (ostream& o, const n_coeffType& type)
136  {
137#define CASE(A) case A: return o << (" " # A) << " ";
138    switch( type )
139    {
140      CASE(n_unknown);
141      CASE(n_Zp);
142      CASE(n_Q);
143      CASE(n_R);
144      CASE(n_GF);
145      CASE(n_long_R);
146      CASE(n_Zp_a);
147      CASE(n_Q_a);
148      CASE(n_long_C);
149      CASE(n_Z);
150      CASE(n_Zn);
151      CASE(n_Zpn);
152      CASE(n_Z2m);
153      CASE(n_CF);
154      default: return o << "Unknown type: [" << (const unsigned long) type << "]"; 
155    }   
156#undef CASE
157    return o;
158  }
159}
160 
161
162bool Test(const n_coeffType type, void* p = NULL)
163{
164  cout  << endl << "----------------------- Testing coeffs: [" << type <<
165                "]: -----------------------" << endl;
166
167  const coeffs r = nInitChar( type, p );
168
169  assume( r != NULL );
170
171  nSetChar( r );
172  assume( getCoeffType(r) == type );
173
174  assume( r->cfInit != NULL );
175  assume( r->cfWrite != NULL );
176  assume( r->cfAdd != NULL );
177  assume( r->cfDelete != NULL );
178
179  if( type == n_Q )
180  {
181    assume( r->cfInit == nlInit );
182    assume( r->cfWrite == nlWrite );
183    assume( r->cfAdd == nlAdd );
184    assume( r->cfDelete == nlDelete );   
185  }
186  else if( type == n_long_R )
187  {
188    assume( r->cfInit == ngfInit );
189    assume( r->cfWrite == ngfWrite );
190    assume( r->cfAdd == ngfAdd );
191    assume( r->cfDelete == ngfDelete );
192  }
193  else if( type == n_long_C )
194  {
195    assume( r->cfInit == ngcInit );
196    assume( r->cfWrite == ngcWrite );
197    assume( r->cfAdd == ngcAdd );
198    assume( r->cfDelete == ngcDelete );   
199  }
200  else if( type == n_R )
201  {
202    assume( r->cfInit == nrInit );
203    assume( r->cfWrite == nrWrite );
204    assume( r->cfAdd == nrAdd );
205//    assume( r->cfDelete == nrDelete ); // No?
206  }
207#ifdef HAVE_RINGS
208  else if( type == n_Z2m )
209  {
210    assume( r->cfInit == nr2mInit );
211    assume( r->cfWrite == nr2mWrite );
212    assume( r->cfAdd == nr2mAdd );
213    assume( r->cfDelete == ndDelete );
214  }
215  else if( type == n_Zn )
216  {
217    assume( r->cfInit == nrnInit );
218    assume( r->cfWrite == nrnWrite );
219    assume( r->cfAdd == nrnAdd );
220    assume( r->cfDelete == nrnDelete );
221  }
222#endif
223  else if( type == n_GF )
224  {
225    assume( r->cfInit == nfInit );
226    assume( r->cfWrite == nfWrite );
227    assume( r->cfAdd == nfAdd );
228    //assume( r->cfDelete == nfDelete );
229  }
230  else
231  {
232    // ...
233  }
234
235  bool ret = Test( r );
236
237  nKillChar( r );
238
239  return ret;
240}
241
242
243
244
245int main()
246{
247  int c = 0;
248 
249  n_coeffType type;
250
251  // rings needed for: n_Zp_a, n_Q_a ?
252
253  type = nRegister( n_Zp, npInitChar); assume( type == n_Zp );
254  if( Test(type, (void*) 11) )
255    c ++;
256
257 
258  type = nRegister( n_Q, nlInitChar); assume( type == n_Q );
259  if( Test(type) )
260    c ++;
261
262  type = nRegister( n_R, nrInitChar); assume( type == n_R );
263  if( Test(type) )
264    c ++;
265
266
267#ifdef HAVE_RINGS
268  type = nRegister( n_Z, nrzInitChar); assume( type == n_Z );
269  if( Test(type) )
270    c ++;
271
272  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m );
273  if( Test(type, (void*) 2) )
274    c ++;
275#endif
276
277
278   type = nRegister( n_GF, nfInitChar); assume( type == n_GF );
279
280   GFInfo param;
281
282   param.GFChar= 5;
283   param.GFSize= 25;
284   param.GFPar_name= "Z";
285
286   if( Test(type, (void*) &param) )
287     c ++;
288 
289
290 
291  TODO(Somebody, floating arithmetics via GMP rely on two global variables (see setGMPFloatDigits). Fix it!);
292 
293  setGMPFloatDigits( 10, 5 ); // Init global variables in mpr_complex.cc for gmp_float's...
294     
295  type = nRegister( n_long_C, ngcInitChar); assume( type == n_long_C );
296  if( Test(type) )
297    c ++;
298
299  type = nRegister( n_long_R, ngfInitChar); assume( type == n_long_R );
300  if( Test(type) )
301    c ++;
302 
303
304  type = nRegister( n_GF, nfInitChar); assume( type == n_GF );
305  if( Test(type) )
306    c ++;
307 
308#ifdef HAVE_RINGS
309  type = nRegister( n_Zn, nrnInitChar); assume( type == n_Zn );
310
311  TODO(Frank, this seems to be a trivial BUG: the parameter 'm' is ignored now in nrnSetExp. Please fix someday!!!)
312  if( Test(type, (void*) 3) )
313    c ++;
314#endif
315
316 
317 
318  return c;
319
320}
Note: See TracBrowser for help on using the repository browser.