001 /*
002 * $Id: SolvableModuleListTest.java 3445 2010-12-25 17:24:04Z kredel $
003 */
004
005 package edu.jas.poly;
006
007 import java.util.List;
008 import java.util.ArrayList;
009
010 import junit.framework.Test;
011 import junit.framework.TestCase;
012 import junit.framework.TestSuite;
013
014 //import edu.jas.structure.RingElem;
015
016 import edu.jas.arith.BigRational;
017
018 //import edu.jas.poly.GenPolynomialRing;
019
020
021 /**
022 * SolvableModuleList tests using JUnit.
023 * @author Heinz Kredel.
024 */
025
026 public class SolvableModuleListTest extends TestCase {
027
028 /**
029 * main.
030 */
031 public static void main (String[] args) {
032 junit.textui.TestRunner.run( suite() );
033 }
034
035 /**
036 * Constructs a <CODE>SolvableModuleListTest</CODE> object.
037 * @param name String.
038 */
039 public SolvableModuleListTest(String name) {
040 super(name);
041 }
042
043 /**
044 * suite.
045 */
046 public static Test suite() {
047 TestSuite suite= new TestSuite(SolvableModuleListTest.class);
048 return suite;
049 }
050
051 //private final static int bitlen = 100;
052
053 ModuleList<BigRational> m;
054 PolynomialList<BigRational> p;
055
056 GenSolvablePolynomial<BigRational> a;
057 GenSolvablePolynomial<BigRational> b;
058 GenSolvablePolynomial<BigRational> c;
059 GenSolvablePolynomial<BigRational> d;
060 GenSolvablePolynomial<BigRational> e;
061
062 BigRational cfac;
063 GenSolvablePolynomialRing<BigRational> pfac;
064
065 int rl = 4;
066 int kl = 4;
067 int ll = 4;
068 int el = 5;
069 float q = 0.5f;
070
071 protected void setUp() {
072 a = b = c = d = e = null;
073 cfac = new BigRational(1);
074 TermOrder tord = new TermOrder();
075 pfac = new GenSolvablePolynomialRing<BigRational>(cfac,rl,tord);
076 m = null;
077 p = null;
078 }
079
080 protected void tearDown() {
081 a = b = c = d = e = null;
082 m = null;
083 p = null;
084 }
085
086
087 /**
088 * Test constructor and toString.
089 *
090 */
091 public void testConstructor() {
092 p = new PolynomialList<BigRational>(pfac,(List<GenPolynomial<BigRational>>)null);
093 assertTrue("p = 0", p.list == null);
094
095 m = new ModuleList<BigRational>(pfac,(List<List<GenPolynomial<BigRational>>>)null);
096 assertTrue("m = 0", m.list == null);
097 }
098
099
100 /**
101 * Test polynomial list.
102 *
103 */
104 public void testPolynomialList() {
105 List<GenPolynomial<BigRational>> l
106 = new ArrayList<GenPolynomial<BigRational>>();
107 for (int i = 0; i < 7; i++) {
108 a = pfac.random(kl, ll+i, el, q );
109 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
110 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
111 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
112 l.add( a );
113 }
114 p = new PolynomialList<BigRational>(pfac,l);
115 //System.out.println("p = "+p);
116
117 assertTrue("p == p", p.equals(p) );
118 assertEquals("p.length", 7, p.list.size() );
119 }
120
121
122 /**
123 * Test module list.
124 *
125 */
126 public void testModuleList() {
127 List<List<GenPolynomial<BigRational>>> l
128 = new ArrayList<List<GenPolynomial<BigRational>>>();
129 for (int i = 0; i < 4; i++) {
130 List<GenPolynomial<BigRational>> r
131 = new ArrayList<GenPolynomial<BigRational>>();
132 for ( int j = 0; j < 3; j++ ) {
133 a = pfac.random(kl, ll, el, q );
134 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
135 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
136 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
137 r.add( a );
138 }
139 l.add( r );
140 }
141 m = new ModuleList<BigRational>(pfac,l);
142 //System.out.println("m = "+m);
143 assertTrue("m == m", m.equals(m) );
144 assertEquals("m.length", 4, m.list.size() );
145 }
146
147
148 /**
149 * Test module and polynomial list.
150 *
151 */
152 public void testModulePolynomialList() {
153 List<List<GenPolynomial<BigRational>>> l
154 = new ArrayList<List<GenPolynomial<BigRational>>>();
155 for (int i = 0; i < 4; i++) {
156 List<GenPolynomial<BigRational>> r
157 = new ArrayList<GenPolynomial<BigRational>>();
158 for ( int j = 0; j < 3; j++ ) {
159 a = pfac.random(kl, ll, el, q );
160 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
161 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
162 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
163 r.add( a );
164 }
165 l.add( r );
166 }
167 m = new ModuleList<BigRational>(pfac,l);
168 //System.out.println("m = "+m);
169 assertTrue("m == m", m.equals(m) );
170 assertEquals("m.length", 4, m.list.size() );
171
172 p = m.getPolynomialList();
173 //System.out.println("p = "+p);
174 assertTrue("p == p", p.equals(p) );
175 assertEquals("p.length", 4, p.list.size() );
176 }
177
178
179 /**
180 * Test module and polynomial and module list.
181 *
182 */
183 public void testModulePolynomialModuleList() {
184 List<List<GenPolynomial<BigRational>>> l
185 = new ArrayList<List<GenPolynomial<BigRational>>>();
186 for (int i = 0; i < 4; i++) {
187 List<GenPolynomial<BigRational>> r
188 = new ArrayList<GenPolynomial<BigRational>>();
189 for ( int j = 0; j < 3; j++ ) {
190 a = pfac.random(kl, ll, el, q );
191 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
192 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
193 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
194 r.add( a );
195 }
196 l.add( r );
197 }
198 m = new ModuleList<BigRational>(pfac,l);
199 //System.out.println("m = "+m);
200 assertTrue("m == m", m.equals(m) );
201 assertEquals("m.length", 4, m.list.size() );
202
203 p = m.getPolynomialList();
204 //System.out.println("p = "+p);
205 assertTrue("p == p", p.equals(p) );
206 assertEquals("p.length", 4, p.list.size() );
207
208 ModuleList<BigRational> m2 = null;
209 m2 = p.getModuleList( 3 );
210 //System.out.println("m2 = "+m2);
211 assertTrue("m2 == m2", m2.equals(m2) );
212 assertEquals("m2.length", 4, m2.list.size() );
213
214 assertTrue("m == m2", m.equals(m2) );
215 }
216
217
218 /**
219 * Test module and polynomial and module and polynomial list.
220 *
221 */
222 public void testModulePolynomialModuleListPolynomial() {
223 List<List<GenPolynomial<BigRational>>> l
224 = new ArrayList<List<GenPolynomial<BigRational>>>();
225 for (int i = 0; i < 4; i++) {
226 List<GenPolynomial<BigRational>> r
227 = new ArrayList<GenPolynomial<BigRational>>();
228 for ( int j = 0; j < 3; j++ ) {
229 a = pfac.random(kl, ll, el, q );
230 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
231 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
232 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
233 r.add( a );
234 }
235 l.add( r );
236 }
237 m = new ModuleList<BigRational>(pfac,l);
238 //System.out.println("m = "+m);
239 assertTrue("m == m", m.equals(m) );
240 assertEquals("m.length", 4, m.list.size() );
241
242 p = m.getPolynomialList();
243 //System.out.println("p = "+p);
244 assertTrue("p == p", p.equals(p) );
245 assertEquals("p.length", 4, p.list.size() );
246
247 ModuleList<BigRational> m2 = null;
248 m2 = p.getModuleList( 3 );
249 //System.out.println("m2 = "+m2);
250 assertTrue("m2 == m2", m2.equals(m2) );
251 assertEquals("m2.length", 4, m2.list.size() );
252
253 assertTrue("m == m2", m.equals(m2) );
254
255 PolynomialList<BigRational> p2 = null;
256 p2 = m2.getPolynomialList();
257 //System.out.println("p2 = "+p2);
258 assertTrue("p2 == p2", p2.equals(p2) );
259 assertEquals("p2.length", 4, p2.list.size() );
260
261 assertTrue("p == p2", p.list.equals(p2.list) );
262 }
263
264
265 /**
266 * Test module and polynomial and module and polynomial list
267 * with WeylRelations.
268 *
269 */
270 public void testWeylModulePolynomialModuleListPolynomial() {
271 int rloc = 4;
272 pfac = new GenSolvablePolynomialRing<BigRational>(cfac,rloc);
273
274 WeylRelations<BigRational> wl = new WeylRelations<BigRational>(pfac);
275 wl.generate();
276 RelationTable table1 = pfac.table;
277 RelationTable table2 = null;
278 RelationTable table3 = null;
279 RelationTable table4 = null;
280 RelationTable table5 = null;
281 //System.out.println("table 1 = " + table1);
282 //System.out.println("ring = " + ring);
283
284 List<List<GenPolynomial<BigRational>>> l
285 = new ArrayList<List<GenPolynomial<BigRational>>>();
286 for (int i = 0; i < 4; i++) {
287 List<GenPolynomial<BigRational>> r
288 = new ArrayList<GenPolynomial<BigRational>>();
289 for ( int j = 0; j < 3; j++ ) {
290 a = pfac.random(kl, ll, el, q );
291 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
292 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
293 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
294 r.add( a );
295 }
296 l.add( r );
297 }
298 m = new ModuleList<BigRational>(pfac,l);
299 //System.out.println("m = "+m);
300 assertTrue("m == m", m.equals(m) );
301 assertEquals("m.length", 4, m.list.size() );
302
303 table2 = ((GenSolvablePolynomialRing<BigRational>)m.ring).table;
304 //System.out.println("table 2 = " + table2);
305 assertEquals("table1 == table2", table1, table2 );
306
307
308 p = m.getPolynomialList();
309 //System.out.println("p = "+p);
310 assertTrue("p == p", p.equals(p) );
311 assertEquals("p.length", 4, p.list.size() );
312
313 table3 = ((GenSolvablePolynomialRing<BigRational>)p.ring).table;
314 //System.out.println("table 3 = " + table3);
315
316 ModuleList<BigRational> m2 = null;
317 m2 = p.getModuleList( 3 );
318 //System.out.println("m2 = "+m2);
319 assertTrue("m2 == m2", m2.equals(m2) );
320 assertEquals("m2.length", 4, m2.list.size() );
321
322 assertTrue("m == m2", m.equals(m2) );
323
324 table4 = ((GenSolvablePolynomialRing<BigRational>)m2.ring).table;
325 //System.out.println("table 4 = " + table4);
326 assertEquals("table2 == table4", table2, table4 );
327 assertEquals("table1 == table4", table1, table4 );
328
329
330 PolynomialList<BigRational> p2 = null;
331 p2 = m2.getPolynomialList();
332 //System.out.println("p2 = "+p2);
333 assertTrue("p2 == p2", p2.equals(p2) );
334 assertEquals("p2.length", 4, p2.list.size() );
335
336 assertTrue("p == p2", p.list.equals(p2.list) );
337 table5 = ((GenSolvablePolynomialRing<BigRational>)p2.ring).table;
338 //System.out.println("table 5= " + table5);
339 assertEquals("table2 == table4", table3.table, table5.table );
340 }
341
342 }