source: git/libpolys/coeffs/test.cc @ 643b1eb

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