1 | |
---|
2 | |
---|
3 | |
---|
4 | #include <misc/auxiliary.h> |
---|
5 | |
---|
6 | #include <factory/factory.h> |
---|
7 | |
---|
8 | #include <omalloc/omalloc.h> |
---|
9 | |
---|
10 | #include <reporter/reporter.h> |
---|
11 | #include <resources/feResource.h> |
---|
12 | |
---|
13 | #include <coeffs/coeffs.h> |
---|
14 | #include <coeffs/numbers.h> |
---|
15 | |
---|
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> |
---|
25 | |
---|
26 | |
---|
27 | #include <iostream> |
---|
28 | |
---|
29 | using namespace std; |
---|
30 | |
---|
31 | #pragma GCC diagnostic ignored "-Wwrite-strings" |
---|
32 | |
---|
33 | void Print(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE) |
---|
34 | { |
---|
35 | n_Test(a,r); |
---|
36 | |
---|
37 | StringSetS(""); |
---|
38 | n_Write(a, r); |
---|
39 | |
---|
40 | |
---|
41 | if( eoln ) |
---|
42 | PrintLn(); |
---|
43 | |
---|
44 | { char* s = StringEndS(); PrintS(s); omFree(s); } |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE) |
---|
49 | { |
---|
50 | Print(a, r, FALSE); |
---|
51 | Print(", of size: %d", n_Size(a, r)); |
---|
52 | |
---|
53 | if( eoln ) |
---|
54 | PrintLn(); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | bool TestArith(const coeffs r) |
---|
60 | { |
---|
61 | number a = n_Init(66666, r); |
---|
62 | |
---|
63 | PrintS("a: "); PrintSized(a, r); |
---|
64 | |
---|
65 | number two = n_Init(2, r); |
---|
66 | |
---|
67 | PrintS("two: "); PrintSized(two, r); |
---|
68 | |
---|
69 | if (n_NumberOfParameters(r) > 0) |
---|
70 | { |
---|
71 | number z = n_Param(1, r); // also any integer instead of 0//? |
---|
72 | |
---|
73 | PrintS("Parameter: "); PrintSized(z, r); |
---|
74 | |
---|
75 | n_Delete(&z, r); |
---|
76 | } |
---|
77 | |
---|
78 | number aa = n_Add(a, a, r); |
---|
79 | |
---|
80 | PrintS("aa = a + a: "); PrintSized(aa, r); |
---|
81 | |
---|
82 | number aa2 = n_Mult(a, two, r); |
---|
83 | |
---|
84 | PrintS("aa2 = a * 2: "); PrintSized(aa2, r); |
---|
85 | |
---|
86 | number aa1 = n_Mult(two, a, r); |
---|
87 | |
---|
88 | PrintS("aa1 = 2 * a: "); PrintSized(aa1, r); |
---|
89 | |
---|
90 | n_Delete(&a, r); |
---|
91 | n_Delete(&two, r); |
---|
92 | |
---|
93 | |
---|
94 | a = n_Sub( aa, aa1, r ); |
---|
95 | |
---|
96 | PrintS("a = aa - aa1: "); PrintSized(a, r); |
---|
97 | |
---|
98 | if( !n_IsZero(a, r) ) |
---|
99 | WarnS("TestArith: ERROR: a != 0 !!!\n"); |
---|
100 | |
---|
101 | n_Delete(&a, r); |
---|
102 | |
---|
103 | a = n_Sub( aa, aa2, r ); |
---|
104 | |
---|
105 | PrintS("a = aa - aa2: "); PrintSized(a, r); |
---|
106 | |
---|
107 | if( !n_IsZero(a, r) ) |
---|
108 | WarnS("TestArith: ERROR: a != 0 !!!\n"); |
---|
109 | |
---|
110 | n_Delete(&a, r); |
---|
111 | |
---|
112 | |
---|
113 | a = n_Sub( aa1, aa2, r ); |
---|
114 | |
---|
115 | PrintS("a = aa1 - aa2: "); PrintSized(a, r); |
---|
116 | |
---|
117 | if( !n_IsZero(a, r) ) |
---|
118 | WarnS("TestArith: ERROR: a != 0 !!!\n"); |
---|
119 | |
---|
120 | n_Delete(&a, r); |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | if( !n_Equal(aa, aa1, r) ) |
---|
125 | WarnS("TestArith: ERROR: aa != aa1 !!!\n"); |
---|
126 | |
---|
127 | if( !n_Equal(aa, aa2, r) ) |
---|
128 | WarnS("TestArith: ERROR: aa != aa2 !!!\n"); |
---|
129 | |
---|
130 | if( !n_Equal(aa1, aa2, r) ) |
---|
131 | WarnS("TestArith: ERROR: aa1 != aa2 !!!\n"); |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | n_Delete(&aa, r); |
---|
137 | n_Delete(&aa1, r); |
---|
138 | n_Delete(&aa2, r); |
---|
139 | |
---|
140 | return false; |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | namespace |
---|
146 | { |
---|
147 | static inline ostream& operator<< (ostream& o, const n_coeffType& type) |
---|
148 | { |
---|
149 | #define CASE(A) case A: return o << (" " # A) << " "; |
---|
150 | switch( type ) |
---|
151 | { |
---|
152 | CASE(n_unknown); |
---|
153 | CASE(n_Zp); |
---|
154 | CASE(n_Q); |
---|
155 | CASE(n_R); |
---|
156 | CASE(n_GF); |
---|
157 | CASE(n_long_R); |
---|
158 | CASE(n_algExt); |
---|
159 | CASE(n_transExt); |
---|
160 | CASE(n_long_C); |
---|
161 | CASE(n_Z); |
---|
162 | CASE(n_Zn); |
---|
163 | CASE(n_Znm); |
---|
164 | CASE(n_Z2m); |
---|
165 | CASE(n_CF); |
---|
166 | default: return o << "Unknown type: [" << (const unsigned long) type << "]"; |
---|
167 | } |
---|
168 | #undef CASE |
---|
169 | return o; |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | bool Test(const n_coeffType type, void* p = NULL) |
---|
175 | { |
---|
176 | cout << endl << "----------------------- Testing coeffs: [" << type << ", " << p << |
---|
177 | "]: -----------------------" << endl; |
---|
178 | |
---|
179 | const coeffs r = nInitChar( type, p ); |
---|
180 | |
---|
181 | if( r == NULL ) { cout << "Test: could not get the specified coeff. domain for type: " << type << " and the parameter: " << p << endl; return false; }; |
---|
182 | |
---|
183 | assume( r != NULL ); |
---|
184 | nSetChar( r ); |
---|
185 | assume( getCoeffType(r) == type ); |
---|
186 | |
---|
187 | assume( r->cfInit != NULL ); |
---|
188 | assume( r->cfWriteLong != NULL ); |
---|
189 | assume( r->cfAdd != NULL ); |
---|
190 | assume( r->cfDelete != NULL ); |
---|
191 | |
---|
192 | if( type == n_Q ) |
---|
193 | { |
---|
194 | assume( r->cfInit == nlInit ); |
---|
195 | assume( r->cfAdd == nlAdd ); |
---|
196 | assume( r->cfDelete == nlDelete ); |
---|
197 | } |
---|
198 | else if( type == n_long_R ) |
---|
199 | { |
---|
200 | assume( r->cfInit == ngfInit ); |
---|
201 | assume( r->cfAdd == ngfAdd ); |
---|
202 | assume( r->cfDelete == ngfDelete ); |
---|
203 | } |
---|
204 | else if( type == n_long_C ) |
---|
205 | { |
---|
206 | // assume( r->cfInit == ngcInit ); |
---|
207 | // assume( r->cfAdd == ngcAdd ); |
---|
208 | // assume( r->cfDelete == ngcDelete ); |
---|
209 | } |
---|
210 | else if( type == n_R ) |
---|
211 | { |
---|
212 | assume( r->cfInit == nrInit ); |
---|
213 | assume( r->cfAdd == nrAdd ); |
---|
214 | // assume( r->cfDelete == nrDelete ); // No? |
---|
215 | } |
---|
216 | #ifdef HAVE_RINGS |
---|
217 | else if( type == n_Z2m ) |
---|
218 | { |
---|
219 | assume( r->cfInit == nr2mInit ); |
---|
220 | assume( r->cfAdd == nr2mAdd ); |
---|
221 | assume( r->cfDelete == ndDelete ); |
---|
222 | } |
---|
223 | else if( type == n_Zn ) |
---|
224 | { |
---|
225 | assume( r->cfInit == nrnInit ); |
---|
226 | assume( r->cfAdd == nrnAdd ); |
---|
227 | assume( r->cfDelete == nrnDelete ); |
---|
228 | } |
---|
229 | #endif |
---|
230 | else if( type == n_GF ) |
---|
231 | { |
---|
232 | // assume( r->cfInit == nfInit ); |
---|
233 | // assume( r->cfAdd == nfAdd ); |
---|
234 | //assume( r->cfDelete == nfDelete ); |
---|
235 | } |
---|
236 | else |
---|
237 | { |
---|
238 | // ... |
---|
239 | } |
---|
240 | |
---|
241 | bool ret = TestArith( r ); |
---|
242 | |
---|
243 | nKillChar( r ); |
---|
244 | |
---|
245 | return ret; |
---|
246 | } |
---|
247 | |
---|
248 | |
---|
249 | int main( int, char *argv[] ) |
---|
250 | { |
---|
251 | assume( sizeof(long) == SIZEOF_LONG ); |
---|
252 | |
---|
253 | if( sizeof(long) != SIZEOF_LONG ) |
---|
254 | { |
---|
255 | WerrorS("Bad config.h: wrong size of long!"); |
---|
256 | |
---|
257 | return(1); |
---|
258 | } |
---|
259 | |
---|
260 | |
---|
261 | feInitResources(argv[0]); |
---|
262 | |
---|
263 | StringSetS("ressources in use (as reported by feStringAppendResources(0):\n"); |
---|
264 | feStringAppendResources(0); |
---|
265 | PrintLn(); |
---|
266 | |
---|
267 | { char* s = StringEndS(); PrintS(s); omFree(s); } |
---|
268 | |
---|
269 | int c = 0; |
---|
270 | |
---|
271 | n_coeffType type; |
---|
272 | |
---|
273 | |
---|
274 | #ifdef HAVE_RINGS |
---|
275 | // TODO(Frank, Segmentation fault! (if used wihout omalloc???). Please_ investigate!); |
---|
276 | type = n_Z2m; |
---|
277 | if( Test(type, (void*) 4) ) |
---|
278 | c ++; |
---|
279 | #endif |
---|
280 | |
---|
281 | type = n_Zp; |
---|
282 | if( Test(type, (void*) 101) ) |
---|
283 | c ++; |
---|
284 | |
---|
285 | #ifdef HAVE_RINGS |
---|
286 | // TODO(Frank, memmory corruption_ if used wihout omalloc??? Please_ investigate!); |
---|
287 | |
---|
288 | type = n_Z2m; |
---|
289 | if( Test(type, (void*) 8) ) |
---|
290 | c ++; |
---|
291 | |
---|
292 | #endif |
---|
293 | |
---|
294 | |
---|
295 | type = n_Q; |
---|
296 | if( Test(type) ) |
---|
297 | c ++; |
---|
298 | |
---|
299 | type = n_R; |
---|
300 | if( Test(type) ) |
---|
301 | c ++; |
---|
302 | |
---|
303 | #ifdef HAVE_RINGS |
---|
304 | type = n_Z; |
---|
305 | if( Test(type) ) |
---|
306 | c ++; |
---|
307 | #endif |
---|
308 | type = n_GF; |
---|
309 | |
---|
310 | |
---|
311 | GFInfo* param = new GFInfo(); |
---|
312 | |
---|
313 | param->GFChar= 5; |
---|
314 | param->GFDegree= 12; |
---|
315 | param->GFPar_name= (const char*)"q"; |
---|
316 | |
---|
317 | if( Test(type, (void*) param) ) |
---|
318 | c ++; |
---|
319 | |
---|
320 | // it should not be used by numbers... right? |
---|
321 | // TODO: what is our policy wrt param-pointer-ownership? |
---|
322 | delete param; |
---|
323 | // Q: no way to deRegister a type? |
---|
324 | |
---|
325 | param = new GFInfo(); |
---|
326 | |
---|
327 | param->GFChar= 5; |
---|
328 | param->GFDegree= 2; |
---|
329 | param->GFPar_name= (const char*)"Q"; |
---|
330 | |
---|
331 | if( Test(type, (void*) param) ) |
---|
332 | c ++; |
---|
333 | |
---|
334 | delete param; |
---|
335 | |
---|
336 | |
---|
337 | |
---|
338 | |
---|
339 | #ifdef HAVE_RINGS |
---|
340 | type = n_Zn; |
---|
341 | |
---|
342 | ZnmInfo Znmparam; |
---|
343 | Znmparam.base= (mpz_ptr) omAlloc (sizeof (mpz_t)); |
---|
344 | mpz_init_set_ui (Znmparam.base, 3); |
---|
345 | Znmparam.exp= 1; |
---|
346 | |
---|
347 | if( Test(type, (void*) &Znmparam) ) |
---|
348 | c ++; |
---|
349 | |
---|
350 | #endif |
---|
351 | |
---|
352 | type = n_long_C; |
---|
353 | if( Test(type) ) |
---|
354 | c ++; |
---|
355 | |
---|
356 | type = n_long_R; |
---|
357 | if( Test(type) ) |
---|
358 | c ++; |
---|
359 | |
---|
360 | #ifdef HAVE_RINGS |
---|
361 | type = n_Z2m; |
---|
362 | if( Test(type, (void*) 2) ) |
---|
363 | c ++; |
---|
364 | #endif |
---|
365 | |
---|
366 | // polynomial rings needed for: n_algExt, n_transExt ! |
---|
367 | |
---|
368 | return c; |
---|
369 | |
---|
370 | } |
---|