1 | #include <omalloc/omalloc.h> |
---|
2 | #include <misc/auxiliary.h> |
---|
3 | |
---|
4 | #include <coeffs/coeffs.h> |
---|
5 | #include <coeffs/numbers.h> |
---|
6 | |
---|
7 | #include <reporter/reporter.h> |
---|
8 | #include <resources/feResource.h> |
---|
9 | |
---|
10 | #include <polys/monomials/ring.h> |
---|
11 | #include <polys/monomials/p_polys.h> |
---|
12 | |
---|
13 | |
---|
14 | BOOLEAN Test(const n_coeffType type, void* param) |
---|
15 | { |
---|
16 | BOOLEAN ret = TRUE; |
---|
17 | |
---|
18 | const coeffs r = nInitChar( type, param ); |
---|
19 | |
---|
20 | if( r == NULL ) |
---|
21 | { |
---|
22 | PrintS( "Test: could not get this coeff. domain" ); PrintLn(); |
---|
23 | return FALSE; |
---|
24 | } |
---|
25 | |
---|
26 | assume( r->cfCoeffWrite != NULLp ); |
---|
27 | |
---|
28 | if( r->cfCoeffWrite != NULL ) |
---|
29 | { |
---|
30 | PrintS( "Coeff-domain: " ); n_CoeffWrite(r); PrintLn(); |
---|
31 | } |
---|
32 | |
---|
33 | number t = n_Init(1, r); |
---|
34 | ndInpAdd(t, t, r); |
---|
35 | |
---|
36 | number two = n_Init(2, r); |
---|
37 | assume(n_Equal(two, t, r)); |
---|
38 | ret = ret && n_Equal(two, t, r); |
---|
39 | n_Delete(&t, r); |
---|
40 | n_Delete(&two, r); |
---|
41 | |
---|
42 | |
---|
43 | const int N = 2; // number of vars |
---|
44 | char* n[N] = {"x", "y"}; // teir names |
---|
45 | |
---|
46 | ring R = rDefault( r, N, n); // now r belongs to R! |
---|
47 | |
---|
48 | if( R == NULL ) |
---|
49 | { |
---|
50 | PrintS( "Test: could not get a polynomial ring over this coeff. domain" ); PrintLn(); |
---|
51 | nKillChar( r ); |
---|
52 | return FALSE; |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | rWrite(R); PrintLn(); |
---|
57 | #define RDEBUG |
---|
58 | #ifdef RDEBUG |
---|
59 | // rDebugPrint(R); PrintLn(); |
---|
60 | #endif |
---|
61 | |
---|
62 | const int exp[N] = {5, 8}; |
---|
63 | |
---|
64 | poly p = p_ISet(1, R); |
---|
65 | assume( p != NULL ); |
---|
66 | assume(pNext(p) == NULL); |
---|
67 | ret = ret && (pNext(p) == NULL); |
---|
68 | |
---|
69 | p_SetExp(p,1,exp[0],R); |
---|
70 | p_SetExp(p,2,exp[1],R); |
---|
71 | p_Setm(p, R); |
---|
72 | |
---|
73 | assume( p_GetExp(p, 1, R) == exp[0] ); |
---|
74 | assume( p_GetExp(p, 2, R) == exp[1] ); |
---|
75 | |
---|
76 | p = p_Add_q(p_Copy(p, R), p, R); |
---|
77 | |
---|
78 | ret = ret && p_EqualPolys(p, p, R); |
---|
79 | |
---|
80 | |
---|
81 | poly p2 = p_ISet(2, R); |
---|
82 | assume( p2 != NULL ); |
---|
83 | assume(pNext(p2) == NULL); |
---|
84 | ret = ret && (pNext(p2) == NULL); |
---|
85 | |
---|
86 | p_SetExp(p2,1,exp[0],R); |
---|
87 | p_SetExp(p2,2,exp[1],R); |
---|
88 | p_Setm(p, R); |
---|
89 | |
---|
90 | assume( p_GetExp(p2, 1, R) == exp[0] ); |
---|
91 | assume( p_GetExp(p2, 2, R) == exp[1] ); |
---|
92 | |
---|
93 | number s = p_GetCoeff(p, R); |
---|
94 | two = n_Init(2, r); |
---|
95 | assume(n_Equal(two, s, r)); |
---|
96 | ret = ret && n_Equal(s, two, r); |
---|
97 | n_Delete(&two, r); |
---|
98 | |
---|
99 | assume(p_EqualPolys(p2, p, R)); |
---|
100 | ret = ret && p_EqualPolys(p, p, R); |
---|
101 | |
---|
102 | p_Delete(&p, R); |
---|
103 | |
---|
104 | p_Delete(&p2, R); |
---|
105 | |
---|
106 | |
---|
107 | rDelete(R); |
---|
108 | |
---|
109 | return ret; |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | BOOLEAN simple(const n_coeffType _type, void* param = NULLp) |
---|
114 | { |
---|
115 | // n_coeffType type = nRegister( _type, p); |
---|
116 | // assume( type == _type ); // ? |
---|
117 | return ( Test(_type, param) ); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | int main( int, char *argv[] ) |
---|
123 | { |
---|
124 | feInitResources(argv[0]); |
---|
125 | |
---|
126 | StringSetS("ressources in use (as reported by feStringAppendResources(0):\n"); |
---|
127 | feStringAppendResources(0); |
---|
128 | { StringAppendS("\n"); char* s = StringEndS(); PrintS(s); omFree(s); } |
---|
129 | // longrat |
---|
130 | if( simple(n_Q) ) |
---|
131 | PrintS("Q: Test Passed!"); |
---|
132 | else |
---|
133 | PrintS("Q: Test: Failed!"); |
---|
134 | PrintLn(); |
---|
135 | |
---|
136 | // modulop |
---|
137 | if( simple(n_Zp, (void*)7) ) |
---|
138 | PrintS("Zp: Test Passed!"); |
---|
139 | else |
---|
140 | PrintS("Zp: Test: Failed!"); |
---|
141 | PrintLn(); |
---|
142 | |
---|
143 | // due to coeffs/ffields.h |
---|
144 | struct |
---|
145 | { |
---|
146 | int GFChar; |
---|
147 | int GFDegree; |
---|
148 | char* GFPar_name; |
---|
149 | } param; |
---|
150 | |
---|
151 | param.GFChar= 5; |
---|
152 | param.GFDegree= 2; |
---|
153 | param.GFPar_name= (const char*)"Q"; |
---|
154 | |
---|
155 | if( simple(n_GF, (void*)¶m) ) |
---|
156 | PrintS("GF: Test Passed!"); |
---|
157 | else |
---|
158 | PrintS("GF: Test: Failed!"); |
---|
159 | PrintLn(); |
---|
160 | |
---|
161 | return 0; |
---|
162 | } |
---|