Changeset 16f8f1 in git for libpolys/coeffs/test.cc


Ignore:
Timestamp:
Mar 3, 2011, 2:26:34 PM (13 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
f47f569bdf07891fa2a30df0f1c5315e6fe1f5d1
Parents:
fb0a6994525982ae391932afdd4d24384a163fda
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-03-03 14:26:34+01:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:01:04+01:00
Message:
ADD: minor changes to coeffs, numbers and tests
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/test.cc

    rfb0a699 r16f8f1  
    2525#pragma GCC diagnostic ignored "-Wwrite-strings"
    2626
    27 bool Test(const coeffs r)
     27void Print(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
     28{
     29  n_Test(a,r);
     30
     31  StringSetS("");
     32  n_Write(a, r);
     33
     34  char* s = NULL;
     35
     36  if( eoln )
     37    s = StringAppend("\n");
     38  else
     39    s = StringAppend("");
     40
     41  PrintS(s);
     42
     43  // free s?
     44}
     45
     46
     47void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
     48{
     49  Print(a, r, FALSE);
     50  Print(", of size: %d", n_Size(a, r));
     51 
     52  if( eoln )
     53    PrintLn();
     54}
     55 
     56
     57
     58bool TestArith(const coeffs r)
    2859{
    2960  number a = n_Init(66666, r);
    3061   
    31   StringSetS("a: ");
    32   n_Test(a,r);
    33   n_Write(a, r);
    34   PrintS(StringAppend("\n"));
     62  PrintS("a: "); PrintSized(a, r);
    3563
    3664  number two = n_Init(2, r);
    3765 
    38   StringSetS("two: ");
    39   n_Test(two,r);
    40   n_Write(two, r);
    41   PrintS(StringAppend("\n"));
     66  PrintS("two: "); PrintSized(two, r);
    4267
    4368  if (getCoeffType(r) == n_GF) //some special test for GF
    4469  {
    45     number z = nfPar (0, r); // also any integer instead of 0
    46     StringSetS("Generator: ");
    47     n_Test(z,r); n_Write (z,r);
    48     PrintS(StringAppend("\n"));
     70    number z = nfPar (0, r); // also any integer instead of 0//?
     71
     72    PrintS("Generator: "); PrintSized(z, r);
     73   
    4974    n_Delete(&z, r);   
    5075  }
     
    5277  number aa = n_Add(a, a, r);
    5378
    54   StringSetS("aa = a + a: ");
    55   n_Test(aa,r); n_Write(aa, r);
    56   PrintS(StringAppend("\n"));
     79  PrintS("aa = a + a: "); PrintSized(aa, r);
    5780 
    5881  number aa2 = n_Mult(a, two, r);
    5982
    60   StringSetS("aa2 = a * 2: ");
    61   n_Test(aa2, r); n_Write(aa2, r);
    62   PrintS(StringAppend("\n"));
     83  PrintS("aa2 = a * 2: "); PrintSized(aa2, r);
    6384
    6485  number aa1 = n_Mult(two, a, r);
    6586 
    66   StringSetS("aa1 = 2 * a: ");
    67   n_Test(aa1,r); n_Write(aa1, r);
    68   PrintS(StringAppend("\n"));
    69 
     87  PrintS("aa1 = 2 * a: "); PrintSized(aa1, r);
    7088
    7189  n_Delete(&a, r);
     
    7593  a = n_Sub( aa, aa1, r );
    7694 
    77   StringSetS("a = aa - aa1: ");
    78   n_Test(a,r); n_Write(a, r);
    79   PrintS(StringAppend("\n"));
     95  PrintS("a = aa - aa1: "); PrintSized(a, r);
    8096
    8197  if( !n_IsZero(a, r) )
    82     WarnS("ERROR: a != 0 !!!\n");
     98    WarnS("TestArith: ERROR: a != 0 !!!\n");
    8399
    84100  n_Delete(&a, r);
    85101
    86 
    87 
    88102  a = n_Sub( aa, aa2, r );
    89103
    90   StringSetS("a = aa - aa2: ");
    91   n_Test(a,r); n_Write(a, r);
    92   PrintS(StringAppend("\n"));
     104  PrintS("a = aa - aa2: "); PrintSized(a, r);
    93105
    94106  if( !n_IsZero(a, r) )
    95     WarnS("ERROR: a != 0 !!!\n");
     107    WarnS("TestArith: ERROR: a != 0 !!!\n");
    96108
    97109  n_Delete(&a, r);
     
    100112  a = n_Sub( aa1, aa2, r );
    101113
    102   StringSetS("a = aa1 - aa2: ");
    103   n_Test(a,r); n_Write(a, r);
    104   PrintS(StringAppend("\n"));
     114  PrintS("a = aa1 - aa2: "); PrintSized(a, r);
    105115
    106116  if( !n_IsZero(a, r) )
    107     WarnS("ERROR: a != 0 !!!\n");
     117    WarnS("TestArith: ERROR: a != 0 !!!\n");
    108118
    109119  n_Delete(&a, r);
     
    112122 
    113123  if( !n_Equal(aa, aa1, r) )
    114     WarnS("ERROR: aa != aa1  !!!\n");
     124    WarnS("TestArith: ERROR: aa != aa1  !!!\n");
    115125
    116126  if( !n_Equal(aa, aa2, r) )
    117     WarnS("ERROR: aa != aa2  !!!\n");
     127    WarnS("TestArith: ERROR: aa != aa2  !!!\n");
    118128
    119129  if( !n_Equal(aa1, aa2, r) )
    120     WarnS("ERROR: aa1 != aa2  !!!\n");
     130    WarnS("TestArith: ERROR: aa1 != aa2  !!!\n");
    121131 
    122132
     
    235245  }
    236246
    237   bool ret = Test( r );
     247  bool ret = TestArith( r );
    238248
    239249  nKillChar( r );
     
    251261  n_coeffType type;
    252262
    253   // rings needed for: n_Zp_a, n_Q_a ?
    254 #ifdef HAVE_RINGS
    255   TODO(Frank, Segmentation fault! (if used wihout omalloc???). Please_ investigate!);
    256 /*
     263
     264#ifdef HAVE_RINGS
     265//  TODO(Frank, Segmentation fault! (if used wihout omalloc???). Please_ investigate!);
     266  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m );
     267  if( Test(type, (void*) 4) )
     268    c ++;
     269#endif
     270
     271  type = nRegister( n_Zp, npInitChar); assume( type == n_Zp );
     272  if( Test(type, (void*) 101) )
     273    c ++;
     274
     275#ifdef HAVE_RINGS
     276//  TODO(Frank, memmory corruption_ if used wihout omalloc??? Please_ investigate!);
     277
     278  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m );
     279  if( Test(type, (void*) 8) )
     280    c ++;
     281
     282#endif
     283
     284 
     285  type = nRegister( n_Q, nlInitChar); assume( type == n_Q );
     286  if( Test(type) )
     287    c ++;
     288
     289  type = nRegister( n_R, nrInitChar); assume( type == n_R );
     290  if( Test(type) )
     291    c ++;
     292
     293#ifdef HAVE_RINGS
     294  type = nRegister( n_Z, nrzInitChar); assume( type == n_Z ); // No need in GMP?
     295  if( Test(type) )
     296    c ++;
     297#endif
     298   type = nRegister( n_GF, nfInitChar); assume( type == n_GF );
     299
     300
     301   GFInfo* param = new GFInfo();
     302
     303   param->GFChar= 5;
     304   param->GFDegree= 12;
     305   param->GFPar_name= (const char*)"q";
     306
     307   if( Test(type, (void*) param) )
     308     c ++;
     309
     310   // it should not be used by numbers... right?
     311   // TODO: what is our policy wrt param-pointer-ownership?
     312   delete param;
     313   // Q: no way to deRegister a type?
     314
     315   param = new GFInfo();
     316
     317   param->GFChar= 5;
     318   param->GFDegree= 2;
     319   param->GFPar_name= (const char*)"Q";
     320
     321   if( Test(type, (void*) param) )
     322     c ++;
     323
     324   delete param;
     325
     326
     327
     328
     329#ifdef HAVE_RINGS
     330//  TODO(Somebody, This will result in memory corruption at Z_2^m later on (due to the succs. setGMPFloatDigits?)...!?); // ????
     331
     332  type = nRegister( n_Zn, nrnInitChar); assume( type == n_Zn );
     333
     334  if( Test(type, (void*) 3) )
     335    c ++;
     336
     337#endif
     338
     339  TODO(Somebody, floating arithmetics via GMP rely on two global variables (see setGMPFloatDigits). Please fix it!);
     340  setGMPFloatDigits( 10, 5 ); // Init global variables in mpr_complex.cc for gmp_float's... // Note that this seems also to be required for Z_2^m (and Zn?)!????
     341
     342
     343  type = nRegister( n_long_C, ngcInitChar); assume( type == n_long_C );
     344  if( Test(type) )
     345    c ++;
     346
     347  type = nRegister( n_long_R, ngfInitChar); assume( type == n_long_R );
     348  if( Test(type) )
     349    c ++;
     350
     351#ifdef HAVE_RINGS
    257352  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m );
    258353  if( Test(type, (void*) 2) )
    259354    c ++;
    260 */
    261 #endif
    262 
    263   type = nRegister( n_Zp, npInitChar); assume( type == n_Zp );
    264   if( Test(type, (void*) 11) )
    265     c ++;
    266 
    267 #ifdef HAVE_RINGS
    268   TODO(Frank, memmory corruption_ if used wihout omalloc??? Please_ investigate!);
    269 /*
    270   type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m );
    271   if( Test(type, (void*) 2) )
    272     c ++;
    273 */   
    274 #endif
    275 
    276  
    277   type = nRegister( n_Q, nlInitChar); assume( type == n_Q );
    278   if( Test(type) )
    279     c ++;
    280 
    281   type = nRegister( n_R, nrInitChar); assume( type == n_R );
    282   if( Test(type) )
    283     c ++;
    284 
    285 #ifdef HAVE_RINGS
    286   type = nRegister( n_Z, nrzInitChar); assume( type == n_Z ); // No need in GMP?
    287   if( Test(type) )
    288     c ++;
    289 #endif
    290    GFInfo param;
    291    type = nRegister( n_GF, nfInitChar); assume( type == n_GF );
    292 
    293 
    294    param.GFChar= 5;
    295    param.GFDegree= 12;
    296    param.GFPar_name= (const char*)"q";
    297 
    298    if( Test(type, (void*) &param) )
    299      c ++;
    300 
    301 
    302    param.GFChar= 5;
    303    param.GFDegree= 2;
    304    param.GFPar_name= (const char*)"Q";
    305 
    306    if( Test(type, (void*) &param) )
    307      c ++;
    308 
    309 
    310   TODO(Somebody, floating arithmetics via GMP rely on two global variables (see setGMPFloatDigits). Please fix it!);
    311 
    312 
    313 
    314 #ifdef HAVE_RINGS
    315   TODO(Somebody, This will result in memory corruption at Z_2^m later on (due to the succs. setGMPFloatDigits?)...!?);
    316 /*
     355#endif
     356
     357
     358#ifdef HAVE_RINGS
    317359  type = nRegister( n_Zn, nrnInitChar); assume( type == n_Zn );
    318360
    319361  if( Test(type, (void*) 3) )
    320362    c ++;
    321 */
    322 #endif
    323 
    324   setGMPFloatDigits( 10, 5 ); // Init global variables in mpr_complex.cc for gmp_float's... // Note that this seems also to be required for Z_2^m (and Zn?)!????
    325 
    326 
    327   type = nRegister( n_long_C, ngcInitChar); assume( type == n_long_C );
    328   if( Test(type) )
    329     c ++;
    330 
    331   type = nRegister( n_long_R, ngfInitChar); assume( type == n_long_R );
    332   if( Test(type) )
    333     c ++;
    334 
    335 #ifdef HAVE_RINGS
    336   type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m );
    337   if( Test(type, (void*) 2) )
    338     c ++;
    339 #endif
    340 
    341 
    342 #ifdef HAVE_RINGS
    343   type = nRegister( n_Zn, nrnInitChar); assume( type == n_Zn );
    344 
    345   if( Test(type, (void*) 3) )
    346     c ++;
    347 #endif
    348  
     363#endif
     364 
     365  // polynomial rings needed for: n_Zp_a, n_Q_a ?
    349366 
    350367  return c;
Note: See TracChangeset for help on using the changeset viewer.