Changeset b27c052 in git


Ignore:
Timestamp:
Apr 27, 2011, 3:09:38 AM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
Children:
f70f641abd84405ed069738ba8c3597d64be24dc
Parents:
6c084af83f830337d6cc5d88e05a66c74d9350f8
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-04-27 03:09:38+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:31:29+01:00
Message:
ADD: first poly-tests (Sum Up integers 0..N)
ADD: GlobalFixup made common and is able to redirect clog
FIX: related minor fixes
Location:
libpolys
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/monomials/p_polys.h

    r6c084af rb27c052  
    220220number    p_GetAllDenom(poly ph, const ring r);
    221221
    222 int       pSize( poly p, const ring r );
     222int       p_Size( poly p, const ring r );
    223223
    224224// homogenizes p by multiplying certain powers of the varnum-th variable
     
    17851785poly      p_Divide(poly a, poly b, const ring r);
    17861786poly      p_DivideM(poly a, poly b, const ring r);
     1787poly      p_Div_nn(poly p, const number n, const ring r);
    17871788void      p_Lcm(poly a, poly b, poly m, const ring r);
    17881789poly      p_Diff(poly a, int k, const ring r);
  • libpolys/tests/Makefile.am

    r6c084af rb27c052  
    1 CXXTEMPLFLAGS = --no-exceptions ## -fno-implicit-templates
     1CXXTEMPLFLAGS = -O0 --no-exceptions ## -fno-implicit-templates
    22
    33## for testing...
     
    1515
    1616
    17 TESTS = simple_test coeffs_test polys_test
     17TESTS = simple_test coeffs_test rings_test polys_test
    1818check_PROGRAMS = $(TESTS)
    1919
     
    2121coeffs_test_SOURCES = coeffs_test_runner.cpp
    2222polys_test_SOURCES = polys_test_runner.cpp
     23rings_test_SOURCES = rings_test_runner.cpp
    2324
    2425
     
    3435
    3536polys_test_LDFLAGS = ${AM_LDFLAGS} $(USEPPROCSDYNAMICLDFLAGS)
     37rings_test_LDFLAGS = $(polys_test_LDFLAGS)
    3638
    3739coeffs_test_LDADD = -lcoeffs_g ${GMP_LIBS} -lresources_g -lreporter_g -lmisc_g -lomalloc_debug
    3840polys_test_LDADD = -lpolys_g $(USEPPROCSDYNAMICLD) $(coeffs_test_LDADD)
     41rings_test_LDADD = $(polys_test_LDADD)
    3942
    4043
    4144
    42 BUILT_SOURCES = $(simple_test_SOURCES) $(coeffs_test_SOURCES) $(polys_test_SOURCES)
     45BUILT_SOURCES = $(simple_test_SOURCES) $(coeffs_test_SOURCES) $(rings_test_SOURCES) $(polys_test_SOURCES)
    4346
    4447
     
    5255polys_test_runner.cpp: polys_test.h
    5356        ${srcdir}/cxxtestgen.pl --no-eh -o $@ --error-printer $^
     57
     58rings_test_runner.cpp: rings_test.h
     59        ${srcdir}/cxxtestgen.pl --no-eh -o $@ --error-printer $^
  • libpolys/tests/coeffs_test.h

    r6c084af rb27c052  
    1 #include <cxxtest/TestSuite.h>
    2 #include <cxxtest/GlobalFixture.h>
    3 
    41#include "config.h"
    52#include <misc/auxiliary.h>
    63#include <omalloc/omalloc.h>
     4
    75
    86#include <reporter/reporter.h>
     
    6260 
    6361    clog<< "N*(N+1)/2: "; PrintSized(res, r);
     62
     63
    6464    number d = n_Sub(res, sum1, r);
    65    
    6665    TS_ASSERT( n_IsZeroDivisor(d, r) );
     66    n_Delete(&d, r);
    6767   
    6868    if( n_GetChar(r) == 0 )
     
    336336}
    337337
    338 
    339 
    340 class GlobalPrintingFixture : public CxxTest::GlobalFixture
    341 {
    342   public:
    343     bool setUpWorld() {
    344       clog << endl << ( "<world>" ) << endl;
    345       feInitResources(argv0);
    346       return true;
    347     }
    348     bool tearDownWorld() { clog << endl <<( "</world>" )  << endl; return true; }
    349     bool setUp() { clog << endl <<( "<test>" )  << endl; return true; }
    350     bool tearDown() { clog << endl <<( "</test>" )  << endl; return true; }
    351 };
    352 
    353 
    354 //
    355338// We can rely on this file being included exactly once
    356339// and declare this global variable in the header file.
  • libpolys/tests/common.h

    r6c084af rb27c052  
    22#define TESTS_COMMON_H
    33
     4#include <iostream>
     5#include <fstream>
     6#include <string.h>
     7
     8#include <cxxtest/TestSuite.h>
     9#include <cxxtest/GlobalFixture.h>
     10
     11#include <omalloc/omalloc.h>
    412#include <misc/auxiliary.h>
    513
     
    715#include <coeffs/numbers.h>
    816
    9 #include <iostream>
     17#include <reporter/reporter.h>
     18#include <resources/feResource.h>
    1019
    1120
     
    7584}
    7685
     86class GlobalPrintingFixture : public CxxTest::GlobalFixture
     87{
     88   std::ofstream _ofs;
     89   bool _redirect;
     90  public:
     91    GlobalPrintingFixture(bool redirect = false): _redirect(redirect){}
     92   
     93    ~GlobalPrintingFixture()
     94    {
     95      if( _ofs)
     96        _ofs.close();
     97    }
     98   
     99    void Redirect()
     100    {
     101      const int ll = strlen(argv0);
     102      const int l = 5 + ll;
     103      char* s = (char *)omAlloc0(l);
     104      s = strncpy(s, argv0, ll);
     105      strncpy(s + ll, ".log", 4);
     106      _ofs.open(s); // , ios_base::out)
     107      omFreeSize((ADDRESS)s, l);
     108
     109      std::clog.rdbuf(_ofs.rdbuf());
     110    }
     111
     112    virtual bool setUpWorld()
     113    {
     114      if( _redirect )
     115        Redirect();
     116
     117      std::clog << std::endl << ( "<world>" ) << std::endl << std::endl;
     118      feInitResources(argv0);
     119      return true;
     120    }
     121
     122    virtual bool tearDownWorld()
     123    {
     124        std::clog << std::endl << std::endl <<( "</world>" )  << std::endl  << std::endl ;
     125        return true;
     126    }
     127    virtual bool setUp() { std::clog << std::endl << std::endl <<( "<test>" ) << std::endl  << std::endl; return true; }
     128    virtual bool tearDown() { std::clog << std::endl << std::endl <<( "</test>" ) << std::endl  << std::endl; return true; }
     129};
     130
    77131
    78132#endif /* TESTS_COMMON_H */
  • libpolys/tests/cxxtestgen.pl

    r6c084af rb27c052  
    536536sub writeMain() {
    537537  if ( $gui ) {
    538     print "char* argv0;\n";
     538    print "char* argv0 = NULL;\n";
    539539    print "int main( int argc, char *argv[] ) {\n";
    540540    print "argv0 = argv[0];\n";
     
    545545  }
    546546  elsif ( $runner ) {
    547     print "char* argv0;\n";
    548     print "int main( int argc, char *argv[] ) {\n";
     547    print "char* argv0 = NULL;\n";
     548    print "int main( int, char *argv[] ) {\n";
    549549    print "argv0 = argv[0];\n";
    550550    $noStaticInit &&
  • libpolys/tests/polys_test.h

    r6c084af rb27c052  
    1 #include <cxxtest/TestSuite.h>
    2 #include <cxxtest/GlobalFixture.h>
    3 
    41#include "config.h"
    5 #include <misc/auxiliary.h>
    6 #include <omalloc/omalloc.h>
    7 
    8 #include <reporter/reporter.h>
    9 #include <resources/feResource.h>
    10 
    11 #include <coeffs/coeffs.h>
    12 #include <coeffs/numbers.h>
    13 
     2
     3#include "common.h"
     4using namespace std;
    145
    156// the following headers are private...
     
    2617
    2718#include <polys/monomials/ring.h>
    28 
    29 #include "common.h"
    30 using namespace std;
    31 
    32 
    33 
    34 class GlobalPrintingFixture : public CxxTest::GlobalFixture
     19#include <polys/monomials/p_polys.h>
     20
     21
     22
     23
     24class MyGlobalPrintingFixture : public GlobalPrintingFixture
    3525{
    3626  public:
    37     bool setUpWorld() {
    38       clog << ( "<world>" ) << endl;
    39       feInitResources(argv0);
     27    virtual bool setUpWorld()
     28    {
     29   
     30      GlobalPrintingFixture::setUpWorld();
    4031     
     32
    4133      TS_ASSERT_EQUALS( nRegister( n_Zp, npInitChar), n_Zp );
    4234      TS_ASSERT_EQUALS( nRegister( n_GF, nfInitChar), n_GF );
     
    5143      return true;
    5244    }
    53     bool tearDownWorld() { clog <<( "</world>" )  << endl; return true; }
    54     bool setUp() { clog <<( "<test>" )  << endl; return true; }
    55     bool tearDown() { clog <<( "</test>" )  << endl; return true; }
    5645};
    5746
     
    6150// and declare this global variable in the header file.
    6251//
    63 static GlobalPrintingFixture globalPrintingFixture;
     52static MyGlobalPrintingFixture globalPrintingFixture;
    6453
    6554
     
    7362  #endif
    7463  }
     64
     65  static inline std::string _2S(poly a, const ring r)
     66  {
     67    p_Test(a,r);
     68   
     69    StringSetS("");
     70    p_Write(a, r);
     71
     72    const char* s = StringAppendS("");
     73
     74    std::stringstream ss;  ss << s;
     75
     76    StringSetS(""); 
     77    return ss.str();
     78  }
     79
     80  static inline void PrintSized(/*const*/ poly a, const ring r, BOOLEAN eoln = TRUE)
     81  {
     82    std::clog << _2S(a, r) << ", of size: " << p_Size(a, r);
     83
     84    if( eoln )
     85      std::clog << std::endl; 
     86  }
     87
     88template <typename T>
     89static inline poly p_Init(T v, const ring r)
     90{ assume(r != NULL); return p_ISet(v, r); }
     91
     92static inline void Delete(poly &p, const ring r)
     93{
     94  if( p != NULL )
     95    p_Delete(&p, r);
     96
     97  p = NULL;
     98}
     99
     100void TestSum(const ring r, const unsigned long N)
     101{
     102  clog << ( _2S("TEST: sum[0..") + _2S(N) + "]: ");
     103  clog << endl;
     104
     105  assume( N > 0 ); // just for now...
     106
     107  const unsigned long ssss = (N * (N+1)) / 2;
     108 
     109  poly sum1 = p_Init(ssss, r);
     110  clog<< "poly(N*(N+1)/2) (int: " << ssss << "): "; PrintSized(sum1, r);
     111
     112  poly s, ss, i, res;
     113
     114  s = p_Init(N  , r);
     115  i = p_Init(N+1, r);
     116
     117  i = p_Mult_q(s, i, r); s = NULL;
     118
     119  clog<< "poly(N)*poly(N+1): (int: "<< N*(N+1) << "): "; PrintSized(i, r); 
     120
     121  number t = n_Init(2, r->cf);
     122  clog<< "number(2): "; PrintSized(i, r); 
     123
     124  if( !n_IsZero( t, r->cf) )
     125  {
     126    TS_ASSERT( n_DivBy(p_GetCoeff(i, r), t, r->cf) );
     127    res = p_Div_nn(i, t, r); i = NULL;
     128 
     129    clog<< "(poly(N)*poly(N+1))/number(2): "; PrintSized(res, r);
     130    poly d = p_Sub(res, sum1, r);
     131   
     132    if( d != NULL )
     133      TS_ASSERT( n_IsZeroDivisor(p_GetCoeff(d, r), r->cf) );
     134   
     135    Delete(d, r);
     136   
     137    if( n_GetChar(r->cf) == 0 )
     138    {
     139      TS_ASSERT( p_EqualPolys(sum1, res, r) );
     140      TS_ASSERT( p_EqualPolys(res, sum1, r) );
     141    }
     142  } else
     143    TS_ASSERT_EQUALS( n_GetChar(r->cf), 2);
     144 
     145  n_Delete(&t, r->cf);
     146
     147
     148  s = p_Init(0  , r);
     149  ss = p_Init(0 , r);
     150  for( int k = N; k >= 0; k-- )
     151  {
     152    i = p_Init(k, r);
     153    s = p_Add_q(s, i, r); // s += i
     154
     155    i = p_Neg( p_Init(k, r), r );
     156    ss = p_Add_q(ss, i, r); // ss -= i
     157  }
     158 
     159  clog<< "ss(-sum): "; PrintSized(ss, r); 
     160
     161  ss = p_Neg(ss, r); // ss = -ss
     162 
     163  clog<< "real sum    : "; PrintSized(s, r);
     164  clog<< "real sum(--): "; PrintSized(ss, r); 
     165
     166  TS_ASSERT( p_EqualPolys(s, ss, r) );
     167  TS_ASSERT( p_EqualPolys(ss, s, r) );
     168
     169  TODO(somebody, fix the delete method!);
     170/*
     171  Delete(sum1, r);
     172  Delete(res, r);
     173
     174  Delete(s, r);   
     175  Delete(ss, r);   
     176*/
     177  clog << ( " >>> TEST DONE!" );
     178  clog << endl;
     179
     180}
     181   
     182void Test(const ring r)
     183{
     184  TestSum( r, 10 );
     185  TestSum( r, 100 );
     186  TestSum( r, 101 );
     187  TestSum( r, 1001 );
     188  TestSum( r, 9000 );
     189}
     190
    75191}
    76192
     
    97213    TS_ASSERT_EQUALS( rVar(r), 1);
    98214
     215    Test(r);
     216     
    99217    rDelete(r);
    100218  }
     
    117235
    118236    TS_ASSERT_EQUALS( rVar(r), 1);
     237
     238    Test(r);
    119239
    120240    rDelete(r);
     
    140260     TS_ASSERT_EQUALS( rVar(r), 3);
    141261
     262     Test(r);
     263     
    142264     rDelete(r);
    143265  }
     
    160282     TS_ASSERT_EQUALS( rVar(r), 4);
    161283
     284     Test(r);
     285     
    162286     rDelete(r);
    163287   }
     
    198322     TS_ASSERT_EQUALS( rVar(r), 1);
    199323
     324     Test(r);
     325
    200326     rDelete(r); // kills 'cf' as well!
    201327   }
Note: See TracChangeset for help on using the changeset viewer.