source: git/libpolys/coeffs/test.cc @ 45cc512

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