001    /*
002     * $Id: ModuleListTest.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    
019    
020    
021    /**
022     * ModuleList tests with JUnit.
023     * @author Heinz Kredel
024     */
025    
026    public class ModuleListTest 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>ModuleListTest</CODE> object.
037     * @param name String.
038     */
039       public ModuleListTest(String name) {
040              super(name);
041       }
042    
043    /**
044     * suite.
045     * @return a test suite.
046     */
047    public static Test suite() {
048         TestSuite suite= new TestSuite(ModuleListTest.class);
049         return suite;
050       }
051    
052       //private final static int bitlen = 100;
053    
054       ModuleList<BigRational> m;
055       PolynomialList<BigRational> p;
056    
057       GenPolynomial<BigRational> a;
058       GenPolynomial<BigRational> b;
059       GenPolynomial<BigRational> c;
060       GenPolynomial<BigRational> d;
061       GenPolynomial<BigRational> e;
062    
063       BigRational cfac;
064       GenPolynomialRing<BigRational> pfac;
065    
066       int rl = 4; 
067       int kl = 4;
068       int ll = 4;
069       int el = 5;
070       float q = 0.5f;
071    
072       protected void setUp() {
073           a = b = c = d = e = null;
074           cfac = new BigRational(1);
075           TermOrder tord = new TermOrder();
076           pfac = new GenPolynomialRing<BigRational>(cfac,rl,tord);
077           m = null;
078           p = null;
079       }
080    
081       protected void tearDown() {
082           a = b = c = d = e = null;
083           m = null;
084           p = null;
085       }
086    
087    
088    /**
089     * Test constructor and toString.
090     * 
091     */
092     public void testConstructor() {
093         p = new PolynomialList<BigRational>(pfac,(List<GenPolynomial<BigRational>>)null);
094         assertTrue("p = 0", p.list == null);
095    
096         m = new ModuleList<BigRational>(pfac,(List<List<GenPolynomial<BigRational>>>)null);
097         assertTrue("m = 0", m.list == null);
098     }
099    
100    
101    /**
102     * Test polynomial list.
103     * 
104     */
105     public void testPolynomialList() {
106         List<GenPolynomial<BigRational>> l 
107             = new ArrayList<GenPolynomial<BigRational>>();
108         for (int i = 0; i < 7; i++) {
109             a = pfac.random(kl, ll+i, el, q );
110             if ( a.isZERO() || a.isONE() ) {
111                 continue;
112             }
113             assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
114             assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
115             assertTrue(" not isONE( a"+i+" )", !a.isONE() );
116             l.add( a );
117         }
118         p = new PolynomialList<BigRational>(pfac,l);
119         //System.out.println("p = "+p);
120    
121         assertTrue("p == p", p.equals(p) );
122         assertEquals("p.length", 7, p.list.size() );
123     }
124    
125    
126    /**
127     * Test module list.
128     * 
129     */
130     public void testModuleList() {
131         List<List<GenPolynomial<BigRational>>> l 
132             = new ArrayList<List<GenPolynomial<BigRational>>>();
133         for (int i = 0; i < 4; i++) {
134             List<GenPolynomial<BigRational>> r 
135                 = new ArrayList<GenPolynomial<BigRational>>();
136             for ( int j = 0; j < 3; j++ ) {
137                 a = pfac.random(kl, ll, el, q );
138                 if ( a.isZERO() || a.isONE() ) {
139                     continue;
140                 }
141                 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
142                 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
143                 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
144                 r.add( a );
145             }
146             l.add( r );
147         }
148         m = new ModuleList<BigRational>(pfac,l);
149         //System.out.println("m = "+m);
150         assertTrue("m == m", m.equals(m) );
151         assertEquals("m.length", 4, m.list.size() );
152     }
153    
154    
155    /**
156     * Test module and polynomial list.
157     * 
158     */
159     public void testModulePolynomialList() {
160         List<List<GenPolynomial<BigRational>>> l 
161             = new ArrayList<List<GenPolynomial<BigRational>>>();
162         for (int i = 0; i < 4; i++) {
163             List<GenPolynomial<BigRational>> r 
164                 = new ArrayList<GenPolynomial<BigRational>>();
165             for ( int j = 0; j < 3; j++ ) {
166                 a = pfac.random(kl, ll, el, q );
167                 if ( a.isZERO() || a.isONE() ) {
168                     continue;
169                 }
170                 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
171                 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
172                 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
173                 r.add( a );
174             }
175             l.add( r );
176         }
177         m = new ModuleList<BigRational>(pfac,l);
178         //System.out.println("m = "+m);
179         assertTrue("m == m", m.equals(m) );
180         assertEquals("m.length", 4, m.list.size() );
181    
182         p = m.getPolynomialList();
183         //System.out.println("p = "+p);
184         assertTrue("p == p", p.equals(p) );
185         assertEquals("p.length", 4, p.list.size() );
186     }
187    
188    
189    /**
190     * Test module and polynomial and module list.
191     * 
192     */
193     public void testModulePolynomialModuleList() {
194         List<List<GenPolynomial<BigRational>>> l 
195             = new ArrayList<List<GenPolynomial<BigRational>>>();
196         for (int i = 0; i < 4; i++) {
197             List<GenPolynomial<BigRational>> r 
198                 = new ArrayList<GenPolynomial<BigRational>>();
199             for ( int j = 0; j < 3; j++ ) {
200                 a = pfac.random(kl, ll, el, q );
201                 if ( a.isZERO() || a.isONE() ) {
202                     continue;
203                 }
204                 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
205                 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
206                 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
207                 r.add( a );
208             }
209             l.add( r );
210         }
211         m = new ModuleList<BigRational>(pfac,l);
212         //System.out.println("m = "+m);
213         assertTrue("m == m", m.equals(m) );
214         assertEquals("m.length", 4, m.list.size() );
215    
216         p = m.getPolynomialList();
217         //System.out.println("p = "+p);
218         assertTrue("p == p", p.equals(p) );
219         assertEquals("p.length", 4, p.list.size() );
220    
221         ModuleList<BigRational> m2 = null;
222         m2 = p.getModuleList( 3 );
223         //System.out.println("m2 = "+m2);
224         assertTrue("m2 == m2", m2.equals(m2) );
225         assertEquals("m2.length", 4, m2.list.size() );
226    
227         assertTrue("m == m2", m.equals(m2) );
228     }
229    
230    
231    /**
232     * Test module and polynomial and module and polynomial list.
233     * 
234     */
235     public void testModulePolynomialModuleListPolynomial() {
236         List<List<GenPolynomial<BigRational>>> l 
237             = new ArrayList<List<GenPolynomial<BigRational>>>();
238         for (int i = 0; i < 4; i++) {
239             List<GenPolynomial<BigRational>> r 
240                 = new ArrayList<GenPolynomial<BigRational>>();
241             for ( int j = 0; j < 3; j++ ) {
242                 a = pfac.random(kl, ll, el, q );
243                 if ( a.isZERO() || a.isONE() ) {
244                     continue;
245                 }
246                 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
247                 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
248                 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
249                 r.add( a );
250             }
251             l.add( r );
252         }
253         m = new ModuleList<BigRational>(pfac,l);
254         //System.out.println("m = "+m);
255         assertTrue("m == m", m.equals(m) );
256         assertEquals("m.length", 4, m.list.size() );
257    
258         p = m.getPolynomialList();
259         //System.out.println("p = "+p);
260         assertTrue("p == p", p.equals(p) );
261         assertEquals("p.length", 4, p.list.size() );
262    
263         ModuleList<BigRational> m2 = null;
264         m2 = p.getModuleList( 3 );
265         //System.out.println("m2 = "+m2);
266         assertTrue("m2 == m2", m2.equals(m2) );
267         assertEquals("m2.length", 4, m2.list.size() );
268    
269         assertTrue("m == m2", m.equals(m2) );
270    
271         PolynomialList<BigRational> p2 = null;
272         p2 = m2.getPolynomialList();
273         //System.out.println("p2 = "+p2);
274         assertTrue("p2 == p2", p2.equals(p2) );
275         assertEquals("p2.length", 4, p2.list.size() );
276    
277         assertTrue("p == p2", p.list.equals(p2.list) );
278     }
279    
280    }