source: git/libpolys/coeffs/test.cc @ 80c703

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