Changeset b27c052 in git
- Timestamp:
- Apr 27, 2011, 3:09:38 AM (12 years ago)
- 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
- Location:
- libpolys
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/monomials/p_polys.h
r6c084af rb27c052 220 220 number p_GetAllDenom(poly ph, const ring r); 221 221 222 int p Size( poly p, const ring r );222 int p_Size( poly p, const ring r ); 223 223 224 224 // homogenizes p by multiplying certain powers of the varnum-th variable … … 1785 1785 poly p_Divide(poly a, poly b, const ring r); 1786 1786 poly p_DivideM(poly a, poly b, const ring r); 1787 poly p_Div_nn(poly p, const number n, const ring r); 1787 1788 void p_Lcm(poly a, poly b, poly m, const ring r); 1788 1789 poly p_Diff(poly a, int k, const ring r); -
libpolys/tests/Makefile.am
r6c084af rb27c052 1 CXXTEMPLFLAGS = - -no-exceptions ## -fno-implicit-templates1 CXXTEMPLFLAGS = -O0 --no-exceptions ## -fno-implicit-templates 2 2 3 3 ## for testing... … … 15 15 16 16 17 TESTS = simple_test coeffs_test polys_test17 TESTS = simple_test coeffs_test rings_test polys_test 18 18 check_PROGRAMS = $(TESTS) 19 19 … … 21 21 coeffs_test_SOURCES = coeffs_test_runner.cpp 22 22 polys_test_SOURCES = polys_test_runner.cpp 23 rings_test_SOURCES = rings_test_runner.cpp 23 24 24 25 … … 34 35 35 36 polys_test_LDFLAGS = ${AM_LDFLAGS} $(USEPPROCSDYNAMICLDFLAGS) 37 rings_test_LDFLAGS = $(polys_test_LDFLAGS) 36 38 37 39 coeffs_test_LDADD = -lcoeffs_g ${GMP_LIBS} -lresources_g -lreporter_g -lmisc_g -lomalloc_debug 38 40 polys_test_LDADD = -lpolys_g $(USEPPROCSDYNAMICLD) $(coeffs_test_LDADD) 41 rings_test_LDADD = $(polys_test_LDADD) 39 42 40 43 41 44 42 BUILT_SOURCES = $(simple_test_SOURCES) $(coeffs_test_SOURCES) $( polys_test_SOURCES)45 BUILT_SOURCES = $(simple_test_SOURCES) $(coeffs_test_SOURCES) $(rings_test_SOURCES) $(polys_test_SOURCES) 43 46 44 47 … … 52 55 polys_test_runner.cpp: polys_test.h 53 56 ${srcdir}/cxxtestgen.pl --no-eh -o $@ --error-printer $^ 57 58 rings_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 4 1 #include "config.h" 5 2 #include <misc/auxiliary.h> 6 3 #include <omalloc/omalloc.h> 4 7 5 8 6 #include <reporter/reporter.h> … … 62 60 63 61 clog<< "N*(N+1)/2: "; PrintSized(res, r); 62 63 64 64 number d = n_Sub(res, sum1, r); 65 66 65 TS_ASSERT( n_IsZeroDivisor(d, r) ); 66 n_Delete(&d, r); 67 67 68 68 if( n_GetChar(r) == 0 ) … … 336 336 } 337 337 338 339 340 class GlobalPrintingFixture : public CxxTest::GlobalFixture341 {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 //355 338 // We can rely on this file being included exactly once 356 339 // and declare this global variable in the header file. -
libpolys/tests/common.h
r6c084af rb27c052 2 2 #define TESTS_COMMON_H 3 3 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> 4 12 #include <misc/auxiliary.h> 5 13 … … 7 15 #include <coeffs/numbers.h> 8 16 9 #include <iostream> 17 #include <reporter/reporter.h> 18 #include <resources/feResource.h> 10 19 11 20 … … 75 84 } 76 85 86 class 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 77 131 78 132 #endif /* TESTS_COMMON_H */ -
libpolys/tests/cxxtestgen.pl
r6c084af rb27c052 536 536 sub writeMain() { 537 537 if ( $gui ) { 538 print "char* argv0 ;\n";538 print "char* argv0 = NULL;\n"; 539 539 print "int main( int argc, char *argv[] ) {\n"; 540 540 print "argv0 = argv[0];\n"; … … 545 545 } 546 546 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"; 549 549 print "argv0 = argv[0];\n"; 550 550 $noStaticInit && -
libpolys/tests/polys_test.h
r6c084af rb27c052 1 #include <cxxtest/TestSuite.h>2 #include <cxxtest/GlobalFixture.h>3 4 1 #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" 4 using namespace std; 14 5 15 6 // the following headers are private... … … 26 17 27 18 #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 24 class MyGlobalPrintingFixture : public GlobalPrintingFixture 35 25 { 36 26 public: 37 bool setUpWorld() { 38 clog << ( "<world>" ) << endl; 39 feInitResources(argv0); 27 virtual bool setUpWorld() 28 { 29 30 GlobalPrintingFixture::setUpWorld(); 40 31 32 41 33 TS_ASSERT_EQUALS( nRegister( n_Zp, npInitChar), n_Zp ); 42 34 TS_ASSERT_EQUALS( nRegister( n_GF, nfInitChar), n_GF ); … … 51 43 return true; 52 44 } 53 bool tearDownWorld() { clog <<( "</world>" ) << endl; return true; }54 bool setUp() { clog <<( "<test>" ) << endl; return true; }55 bool tearDown() { clog <<( "</test>" ) << endl; return true; }56 45 }; 57 46 … … 61 50 // and declare this global variable in the header file. 62 51 // 63 static GlobalPrintingFixture globalPrintingFixture;52 static MyGlobalPrintingFixture globalPrintingFixture; 64 53 65 54 … … 73 62 #endif 74 63 } 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 88 template <typename T> 89 static inline poly p_Init(T v, const ring r) 90 { assume(r != NULL); return p_ISet(v, r); } 91 92 static inline void Delete(poly &p, const ring r) 93 { 94 if( p != NULL ) 95 p_Delete(&p, r); 96 97 p = NULL; 98 } 99 100 void 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 182 void 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 75 191 } 76 192 … … 97 213 TS_ASSERT_EQUALS( rVar(r), 1); 98 214 215 Test(r); 216 99 217 rDelete(r); 100 218 } … … 117 235 118 236 TS_ASSERT_EQUALS( rVar(r), 1); 237 238 Test(r); 119 239 120 240 rDelete(r); … … 140 260 TS_ASSERT_EQUALS( rVar(r), 3); 141 261 262 Test(r); 263 142 264 rDelete(r); 143 265 } … … 160 282 TS_ASSERT_EQUALS( rVar(r), 4); 161 283 284 Test(r); 285 162 286 rDelete(r); 163 287 } … … 198 322 TS_ASSERT_EQUALS( rVar(r), 1); 199 323 324 Test(r); 325 200 326 rDelete(r); // kills 'cf' as well! 201 327 }
Note: See TracChangeset
for help on using the changeset viewer.