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