source: git/libpolys/coeffs/test.cc @ 2b6e44

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