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

fieker-DuValspielwiese
Last change on this file since e76d8cb 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
RevLine 
[691dba]1#include "config.h"
[18cb65]2#include <misc/auxiliary.h>
[31f1262]3
4#ifdef HAVE_FACTORY
5#include <factory/factory.h>
6#endif
7
[1820e7]8#include <omalloc/omalloc.h>
9
10#include <reporter/reporter.h>
[f323dd1]11#include <findexec/feResource.h>
[1112b76]12
[2d805a]13#include <coeffs/coeffs.h>
14#include <coeffs/numbers.h>
[c3d175]15
[2d805a]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>
[9eb0f9]25
26
[abb4787]27#ifdef HAVE_FACTORY
[e4fe2b]28int initializeGMP(void){ return 1; }
29int mmInit(void) {return 1; } // ? due to SINGULAR!!!...???
[abb4787]30#endif
[c3d175]31
[56abc3]32#include <iostream>
[17d2dd]33
[56abc3]34using namespace std;
35
[7c362e]36#pragma GCC diagnostic ignored "-Wwrite-strings"
37
[16f8f1]38void Print(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
[c3d175]39{
[2bd9ca]40  n_Test(a,r);
[16f8f1]41
42  StringSetS("");
[17d2dd]43  n_Write(a, r);
[16f8f1]44
45
46  if( eoln ) 
[80c703]47    PrintLn();
[16f8f1]48
[80c703]49  { char* s = StringEndS(); PrintS(s); omFree(s); }
[16f8f1]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);
[17d2dd]69
70  number two = n_Init(2, r);
71 
[16f8f1]72  PrintS("two: "); PrintSized(two, r);
[17d2dd]73
[7fee876]74  if (n_NumberOfParameters(r) > 0) 
[dc06550]75  {
[7fee876]76    number z = n_Param(1, r); // also any integer instead of 0//?
[16f8f1]77
[7fee876]78    PrintS("Parameter: "); PrintSized(z, r);
[16f8f1]79   
[7c362e]80    n_Delete(&z, r);   
[dc06550]81  }
82 
[17d2dd]83  number aa = n_Add(a, a, r);
84
[16f8f1]85  PrintS("aa = a + a: "); PrintSized(aa, r);
[5dcc9a6]86 
[17d2dd]87  number aa2 = n_Mult(a, two, r);
88
[16f8f1]89  PrintS("aa2 = a * 2: "); PrintSized(aa2, r);
[17d2dd]90
91  number aa1 = n_Mult(two, a, r);
92 
[16f8f1]93  PrintS("aa1 = 2 * a: "); PrintSized(aa1, r);
[56abc3]94
[b12b7c]95  n_Delete(&a, r);
[17d2dd]96  n_Delete(&two, r);
97
[2e6a06]98
99  a = n_Sub( aa, aa1, r );
100 
[16f8f1]101  PrintS("a = aa - aa1: "); PrintSized(a, r);
[2e6a06]102
103  if( !n_IsZero(a, r) )
[16f8f1]104    WarnS("TestArith: ERROR: a != 0 !!!\n");
[2e6a06]105
106  n_Delete(&a, r);
107
108  a = n_Sub( aa, aa2, r );
109
[16f8f1]110  PrintS("a = aa - aa2: "); PrintSized(a, r);
[2e6a06]111
112  if( !n_IsZero(a, r) )
[16f8f1]113    WarnS("TestArith: ERROR: a != 0 !!!\n");
[2e6a06]114
115  n_Delete(&a, r);
116
117
118  a = n_Sub( aa1, aa2, r );
119
[16f8f1]120  PrintS("a = aa1 - aa2: "); PrintSized(a, r);
[2e6a06]121
122  if( !n_IsZero(a, r) )
[16f8f1]123    WarnS("TestArith: ERROR: a != 0 !!!\n");
[2e6a06]124
125  n_Delete(&a, r);
126
127
[17d2dd]128 
129  if( !n_Equal(aa, aa1, r) )
[16f8f1]130    WarnS("TestArith: ERROR: aa != aa1  !!!\n");
[17d2dd]131
132  if( !n_Equal(aa, aa2, r) )
[16f8f1]133    WarnS("TestArith: ERROR: aa != aa2  !!!\n");
[17d2dd]134
135  if( !n_Equal(aa1, aa2, r) )
[16f8f1]136    WarnS("TestArith: ERROR: aa1 != aa2  !!!\n");
[17d2dd]137 
138
139 
140
141  n_Delete(&aa, r);
142  n_Delete(&aa1, r);
143  n_Delete(&aa2, r);
[56abc3]144
145  return false;
146}
147
148
149
[17d2dd]150namespace
[56abc3]151{
[17d2dd]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);
[141342]163      CASE(n_algExt);
164      CASE(n_transExt);
[17d2dd]165      CASE(n_long_C);
166      CASE(n_Z);
167      CASE(n_Zn);
[ea25bc]168      CASE(n_Znm);
[17d2dd]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;
[2e6a06]175  }
176}
[17d2dd]177 
[56abc3]178
[17d2dd]179bool Test(const n_coeffType type, void* p = NULL)
180{
[fb0a699]181  cout  << endl << "----------------------- Testing coeffs: [" << type << ", " << p << 
[f1c465f]182                "]: -----------------------" << endl;
[c3d175]183
[1112b76]184  const coeffs r = nInitChar( type, p );
[c3d175]185
[fb0a699]186  if( r == NULL ) { cout << "Test: could not get the specified coeff. domain for type: " << type << " and the parameter: " << p << endl; return false; };
[56abc3]187
[fb0a699]188  assume( r != NULL );
[2b957a]189  nSetChar( r );
190  assume( getCoeffType(r) == type );
[c3d175]191
192  assume( r->cfInit != NULL );
[ce1f78]193  assume( r->cfWriteLong != NULL );
[c3d175]194  assume( r->cfAdd != NULL );
195  assume( r->cfDelete != NULL );
[56abc3]196
[c3d175]197  if( type == n_Q )
198  {
199    assume( r->cfInit == nlInit );
200    assume( r->cfAdd == nlAdd );
201    assume( r->cfDelete == nlDelete );   
[2b957a]202  }
[1c3d1f]203  else if( type == n_long_R )
204  {
205    assume( r->cfInit == ngfInit );
206    assume( r->cfAdd == ngfAdd );
207    assume( r->cfDelete == ngfDelete );
208  }
[c3d175]209  else if( type == n_long_C )
210  {
[7fee876]211//     assume( r->cfInit == ngcInit );
212//     assume( r->cfAdd == ngcAdd );
213//     assume( r->cfDelete == ngcDelete );   
[c3d175]214  }
[2b957a]215  else if( type == n_R )
216  {
217    assume( r->cfInit == nrInit );
218    assume( r->cfAdd == nrAdd );
219//    assume( r->cfDelete == nrDelete ); // No?
[21dc6a]220  }
[f1c465f]221#ifdef HAVE_RINGS
[21dc6a]222  else if( type == n_Z2m )
223  {
224    assume( r->cfInit == nr2mInit );
225    assume( r->cfAdd == nr2mAdd );
[e5ffec7]226    assume( r->cfDelete == ndDelete );
[21dc6a]227  }
228  else if( type == n_Zn )
229  {
230    assume( r->cfInit == nrnInit );
[e5ffec7]231    assume( r->cfAdd == nrnAdd );
232    assume( r->cfDelete == nrnDelete );
[21dc6a]233  }
[dc06550]234#endif
235  else if( type == n_GF )
236  {
[7fee876]237//     assume( r->cfInit == nfInit );
238//     assume( r->cfAdd == nfAdd );
[dc06550]239    //assume( r->cfDelete == nfDelete );
240  }
[21dc6a]241  else
[2b957a]242  {
243    // ...
244  }
[c3d175]245
[16f8f1]246  bool ret = TestArith( r );
[56abc3]247
248  nKillChar( r );
249
250  return ret;
251}
252
253
[9eb0f9]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);
[80c703]260  PrintLn();
[c3d175]261
[80c703]262  { char* s = StringEndS(); PrintS(s); omFree(s); }
[56abc3]263
264  int c = 0;
[c3d175]265 
[56abc3]266  n_coeffType type;
[d61b83a]267
[16f8f1]268
[f85d3e]269#ifdef HAVE_RINGS
[16f8f1]270//  TODO(Frank, Segmentation fault! (if used wihout omalloc???). Please_ investigate!);
[7af488e]271  type =  n_Z2m;
[16f8f1]272  if( Test(type, (void*) 4) )
[f85d3e]273    c ++;
274#endif
[0e4b5f]275
[7af488e]276  type =  n_Zp;
[16f8f1]277  if( Test(type, (void*) 101) )
[0e4b5f]278    c ++;
279
[f85d3e]280#ifdef HAVE_RINGS
[16f8f1]281//  TODO(Frank, memmory corruption_ if used wihout omalloc??? Please_ investigate!);
282
[7af488e]283  type = n_Z2m;
[16f8f1]284  if( Test(type, (void*) 8) )
[f85d3e]285    c ++;
[16f8f1]286
[f85d3e]287#endif
288
[56abc3]289 
[7af488e]290  type =  n_Q;
[1c3d1f]291  if( Test(type) )
292    c ++;
[2b957a]293
[7af488e]294  type = n_R;
[56abc3]295  if( Test(type) )
296    c ++;
297
[0e4b5f]298#ifdef HAVE_RINGS
[7af488e]299  type = n_Z;
[bec902b]300  if( Test(type) )
301    c ++;
[17d2dd]302#endif
[7af488e]303   type = n_GF;
[2e6a06]304
[dc06550]305
[16f8f1]306   GFInfo* param = new GFInfo();
[2e6a06]307
[16f8f1]308   param->GFChar= 5;
309   param->GFDegree= 12;
310   param->GFPar_name= (const char*)"q";
311
312   if( Test(type, (void*) param) )
[0d5a99]313     c ++;
[fb0a699]314
[16f8f1]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();
[fb0a699]321
[16f8f1]322   param->GFChar= 5;
323   param->GFDegree= 2;
324   param->GFPar_name= (const char*)"Q";
[f85d3e]325
[16f8f1]326   if( Test(type, (void*) param) )
[f85d3e]327     c ++;
328
[16f8f1]329   delete param;
[fb0a699]330
[f85d3e]331
332
333
334#ifdef HAVE_RINGS
[7af488e]335  type = n_Zn;
[f85d3e]336
[c3304a]337  ZnmInfo Znmparam;
338  Znmparam.base= (mpz_ptr) omAlloc (sizeof (mpz_t));
339  mpz_init_set_ui (Znmparam.base, 3);
340  Znmparam.exp= 1;
[16f8f1]341
[c3304a]342  if( Test(type, (void*) &Znmparam) )
[c7d05f]343    c ++;
[c3304a]344
[f85d3e]345#endif
346
[7af488e]347  type = n_long_C;
[2e6a06]348  if( Test(type) )
349    c ++;
[17d2dd]350
[7af488e]351  type = n_long_R;
[2e6a06]352  if( Test(type) )
353    c ++;
[f85d3e]354
355#ifdef HAVE_RINGS
[7af488e]356  type = n_Z2m;
[f85d3e]357  if( Test(type, (void*) 2) )
358    c ++;
359#endif
360
[141342]361  // polynomial rings needed for: n_algExt, n_transExt !
[0e4b5f]362 
[56abc3]363  return c;
[2b957a]364
[c3d175]365}
Note: See TracBrowser for help on using the repository browser.