source: git/libpolys/coeffs/test.cc @ fb0a699

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