source: git/libpolys/coeffs/test.cc @ 75f460

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