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

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