Changeset c28ecf in git for libpolys/tests


Ignore:
Timestamp:
May 19, 2011, 2:52:08 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
4a2260efc22c19ac8eaf58d529af8decbb9420bb
Parents:
f0b01f1bf67efed9ec49d9df0d55f75284f5d968
git-author:
Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-05-19 14:52:08+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:36:12+01:00
Message:
alg ext implementation now passing all coeffs and polys tests
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/tests/polys_test.h

    rf0b01f rc28ecf  
    208208class PolysTestSuite : public CxxTest::TestSuite
    209209{
     210private:
     211  void TestArithCf(const coeffs r)
     212  {
     213    clog << ("TEST: Simple Arithmetics: ");
     214    clog << endl;
     215
     216    number two = n_Init(2, r);
     217
     218    number t = n_Init(1, r); 
     219    ndInpAdd(t, t, r); 
     220    TS_ASSERT( n_Equal(two, t, r) );
     221    n_Delete(&t, r);
     222 
     223    if( getCoeffType(r) == n_Q )
     224    {
     225      number t = n_Init(1, r); 
     226      nlInpAdd(t, t, r);
     227      TS_ASSERT( n_Equal(two, t, r) );
     228      n_Delete(&t, r);
     229    }
     230 
     231    const int N = 66666;
     232
     233    number a = n_Init(N, r);
     234   
     235    clog<< "a: "; PrintSized(a, r);
     236
     237    clog<< "two: "; PrintSized(two, r);
     238
     239    number aa0 = n_Init(N*2, r);
     240
     241    number aa = n_Add(a, a, r);
     242
     243    clog<< "aa = a + a: "; PrintSized(aa, r);
     244 
     245    number aa2 = n_Mult(a, two, r);
     246
     247    clog<< "aa2 = a * 2: "; PrintSized(aa2, r);
     248
     249    number aa1 = n_Mult(two, a, r);
     250 
     251    clog<< "aa1 = 2 * a: "; PrintSized(aa1, r);
     252
     253    n_Delete(&a, r);
     254    n_Delete(&two, r);
     255
     256    a = n_Sub( aa, aa1, r );
     257 
     258    clog<< "a = aa - aa1: "; PrintSized(a, r);
     259
     260    TS_ASSERT( n_IsZero(a, r) );
     261
     262    n_Delete(&a, r);
     263
     264    a = n_Sub( aa, aa2, r );
     265
     266    clog<< "a = aa - aa2: "; PrintSized(a, r);
     267
     268    TS_ASSERT( n_IsZero(a, r) );
     269
     270    n_Delete(&a, r);
     271
     272    a = n_Sub( aa1, aa2, r );
     273
     274    clog<< "a = aa1 - aa2: "; PrintSized(a, r);
     275
     276    TS_ASSERT( n_IsZero(a, r) );
     277
     278    n_Delete(&a, r);
     279
     280    TS_ASSERT( n_Equal(aa, aa1, r) );
     281    TS_ASSERT( n_Equal(aa, aa2, r) );
     282    TS_ASSERT( n_Equal(aa1, aa2, r) );
     283 
     284    TS_ASSERT( n_Equal(aa0, aa, r) );
     285    TS_ASSERT( n_Equal(aa0, aa1, r) );
     286    TS_ASSERT( n_Equal(aa0, aa2, r) );
     287
     288    n_Delete(&aa, r);
     289    n_Delete(&aa1, r);
     290    n_Delete(&aa2, r);
     291
     292    n_Delete(&aa0, r);
     293
     294    clog << ( " >>> TEST DONE!" );
     295    clog << endl;
     296  }
     297  void TestSumCf(const coeffs r, const unsigned long N)
     298  {
     299    clog << ( _2S("TEST: sum[0..") + _2S(N) + "]: ");
     300    clog << endl;
     301
     302    assume( N > 0 ); // just for now...
     303
     304    const unsigned long ssss = (N * (N+1)) / 2;
     305   
     306    number sum1 = n_Init(ssss, r);
     307    clog<< "N*(N+1)/2 (int: " << ssss << "): "; PrintSized(sum1, r);
     308
     309    number s, ss, i, res;
     310
     311    s = n_Init(N  , r);
     312    i = n_Init(N+1, r);
     313    ndInpMult(s, i, r);
     314    n_Delete(&i, r);
     315   
     316    clog<< "N*(N+1): ("<< N*(N+1) << ")"; PrintSized(s, r); 
     317   
     318    i = n_Init(2, r);
     319    clog<< "2: "; PrintSized(i, r); 
     320
     321    if( !n_IsZero( i, r) )
     322    {
     323  #ifdef HAVE_RINGS
     324      TS_ASSERT( n_DivBy(s, i, r) );
     325  #endif
     326       
     327      res = n_Div(s, i, r);
     328   
     329      clog<< "N*(N+1)/2: "; PrintSized(res, r);
     330
     331
     332      number d = n_Sub(res, sum1, r);
     333      TS_ASSERT( n_IsZeroDivisor(d, r) );
     334      n_Delete(&d, r);
     335     
     336      if( n_GetChar(r) == 0 )
     337      {
     338        TS_ASSERT( n_Equal(sum1, res, r) );
     339        TS_ASSERT( n_Equal(res, sum1, r) );
     340      }
     341    } else
     342      TS_ASSERT_EQUALS( n_GetChar(r), 2);
     343   
     344
     345    n_Delete(&s, r);  n_Delete(&i, r);
     346   
     347    n_Delete(&sum1, r); n_Delete(&res, r);   
     348   
     349
     350    s = n_Init(0  , r);
     351    ss = n_Init(0 , r);
     352    for( int k = N; k >= 0; k-- )
     353    {
     354      i = n_Init(k, r);
     355      ndInpAdd(s, i, r); // s += i
     356
     357      i = n_Neg(i, r);
     358      ndInpAdd(ss, i, r); // ss -= i
     359     
     360      n_Delete(&i, r);   
     361    }
     362    clog<< "ss: "; PrintSized(ss, r); 
     363
     364    ss = n_Neg(ss, r); // ss = -ss
     365   
     366    clog<< "real sum    : "; PrintSized(s, r);
     367    clog<< "real sum(--): "; PrintSized(ss, r); 
     368
     369    TS_ASSERT( n_Equal(s, ss, r) );
     370    TS_ASSERT( n_Equal(ss, s, r) );
     371
     372    n_Delete(&s, r);   
     373    n_Delete(&ss, r);   
     374
     375    clog << ( " >>> TEST DONE!" );
     376    clog << endl;
     377
     378  }
    210379public:
    211380  void test_Z13_t()
     
    388557
    389558    TS_ASSERT_DIFFERS( cf->cfCoeffWrite, NULLp );
    390    
    391    
    392559 
    393560    if( cf->cfCoeffWrite != NULL )
     
    396563      n_CoeffWrite(cf); PrintLn();
    397564    }
     565   
     566    // some tests for the coefficient field represented by cf:
     567    TestArithCf(cf);
     568    TestSumCf(cf, 10);
     569    TestSumCf(cf, 100);
     570    TestSumCf(cf, 101);
     571    TestSumCf(cf, 1001);
     572    TestSumCf(cf, 9000);
    398573
    399574    clog << "Finally create the polynomial ring (Q[a]/<a2+1>)[x, y]..."
     
    416591    TS_ASSERT_EQUALS(rVar(s), 2);
    417592
    418     //Test(s);
     593    Test(s);
    419594
    420595    rDelete(s); // kills 'cf' and 'r' as well
Note: See TracChangeset for help on using the changeset viewer.