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

spielwiese
Last change on this file since 2d805a was 2d805a, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
Fixed to "#include <component/header.h>" (even for config.h!)
  • Property mode set to 100644
File size: 7.0 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 <<
166                "]: -----------------------" << endl;
167
168  const coeffs r = nInitChar( type, p );
169
170  if( r == NULL ) { cout << "error"; return false; };
171
172  nSetChar( r );
173  assume( getCoeffType(r) == type );
174
175  assume( r->cfInit != NULL );
176  assume( r->cfWrite != NULL );
177  assume( r->cfAdd != NULL );
178  assume( r->cfDelete != NULL );
179
180  if( type == n_Q )
181  {
182    assume( r->cfInit == nlInit );
183    assume( r->cfWrite == nlWrite );
184    assume( r->cfAdd == nlAdd );
185    assume( r->cfDelete == nlDelete );   
186  }
187  else if( type == n_long_R )
188  {
189    assume( r->cfInit == ngfInit );
190    assume( r->cfWrite == ngfWrite );
191    assume( r->cfAdd == ngfAdd );
192    assume( r->cfDelete == ngfDelete );
193  }
194  else if( type == n_long_C )
195  {
196    assume( r->cfInit == ngcInit );
197    assume( r->cfWrite == ngcWrite );
198    assume( r->cfAdd == ngcAdd );
199    assume( r->cfDelete == ngcDelete );   
200  }
201  else if( type == n_R )
202  {
203    assume( r->cfInit == nrInit );
204    assume( r->cfWrite == nrWrite );
205    assume( r->cfAdd == nrAdd );
206//    assume( r->cfDelete == nrDelete ); // No?
207  }
208#ifdef HAVE_RINGS
209  else if( type == n_Z2m )
210  {
211    assume( r->cfInit == nr2mInit );
212    assume( r->cfWrite == nr2mWrite );
213    assume( r->cfAdd == nr2mAdd );
214    assume( r->cfDelete == ndDelete );
215  }
216  else if( type == n_Zn )
217  {
218    assume( r->cfInit == nrnInit );
219    assume( r->cfWrite == nrnWrite );
220    assume( r->cfAdd == nrnAdd );
221    assume( r->cfDelete == nrnDelete );
222  }
223#endif
224  else if( type == n_GF )
225  {
226    assume( r->cfInit == nfInit );
227    assume( r->cfWrite == nfWrite );
228    assume( r->cfAdd == nfAdd );
229    //assume( r->cfDelete == nfDelete );
230  }
231  else
232  {
233    // ...
234  }
235
236  bool ret = Test( r );
237
238  nKillChar( r );
239
240  return ret;
241}
242
243
244
245
246int main()
247{
248  int c = 0;
249 
250  n_coeffType type;
251
252  // rings needed for: n_Zp_a, n_Q_a ?
253#ifdef HAVE_RINGS
254  TODO(Frank, Segmentation fault! (if used wihout omalloc???). Please_ investigate!);
255/*
256  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m );
257  if( Test(type, (void*) 2) )
258    c ++;
259*/
260#endif
261
262  type = nRegister( n_Zp, npInitChar); assume( type == n_Zp );
263  if( Test(type, (void*) 11) )
264    c ++;
265
266#ifdef HAVE_RINGS
267  TODO(Frank, memmory corruption_ if used wihout omalloc??? Please_ investigate!);
268/*
269  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m );
270  if( Test(type, (void*) 2) )
271    c ++;
272*/   
273#endif
274
275 
276  type = nRegister( n_Q, nlInitChar); assume( type == n_Q );
277  if( Test(type) )
278    c ++;
279
280  type = nRegister( n_R, nrInitChar); assume( type == n_R );
281  if( Test(type) )
282    c ++;
283
284#ifdef HAVE_RINGS
285  type = nRegister( n_Z, nrzInitChar); assume( type == n_Z ); // No need in GMP?
286  if( Test(type) )
287    c ++;
288#endif
289
290   type = nRegister( n_GF, nfInitChar); assume( type == n_GF );
291
292   GFInfo param;
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   param.GFChar= 5;
302   param.GFDegree= 2;
303   param.GFPar_name= (const char*)"Q";
304
305   if( Test(type, (void*) &param) )
306     c ++;
307
308  TODO(Somebody, floating arithmetics via GMP rely on two global variables (see setGMPFloatDigits). Please fix it!);
309
310
311
312#ifdef HAVE_RINGS
313  TODO(Somebody, This will result in memory corruption at Z_2^m later on (due to the succs. setGMPFloatDigits?)...!?);
314/*
315  type = nRegister( n_Zn, nrnInitChar); assume( type == n_Zn );
316
317  if( Test(type, (void*) 3) )
318    c ++;
319*/
320#endif
321
322  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?)!????
323
324
325  type = nRegister( n_long_C, ngcInitChar); assume( type == n_long_C );
326  if( Test(type) )
327    c ++;
328
329  type = nRegister( n_long_R, ngfInitChar); assume( type == n_long_R );
330  if( Test(type) )
331    c ++;
332
333#ifdef HAVE_RINGS
334  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m ); 
335  if( Test(type, (void*) 2) )
336    c ++;
337#endif
338
339
340#ifdef HAVE_RINGS
341  type = nRegister( n_Zn, nrnInitChar); assume( type == n_Zn );
342
343  if( Test(type, (void*) 3) )
344    c ++;
345#endif
346 
347 
348  return c;
349
350}
Note: See TracBrowser for help on using the repository browser.