001 /*
002 * $Id: PolynomialListTest.java 551 2006-01-29 13:02:07Z kredel $
003 */
004
005 package edu.jas.poly;
006
007 import java.util.ArrayList;
008 import java.util.List;
009
010 import junit.framework.Test;
011 import junit.framework.TestCase;
012 import junit.framework.TestSuite;
013 import edu.jas.arith.BigRational;
014
015
016 /**
017 * PolynomialList Test using JUnit.
018 * @author Heinz Kredel
019 */
020
021 public class PolynomialListTest extends TestCase {
022
023 /**
024 * main.
025 */
026 public static void main (String[] args) {
027 junit.textui.TestRunner.run( suite() );
028 }
029
030 /**
031 * Constructs a <CODE>PolynomialListTest</CODE> object.
032 * @param name String.
033 */
034 public PolynomialListTest(String name) {
035 super(name);
036 }
037
038 /**
039 */
040 public static Test suite() {
041 TestSuite suite= new TestSuite(PolynomialListTest.class);
042 return suite;
043 }
044
045 //private final static int bitlen = 100;
046
047 GenPolynomialRing<BigRational> fac;
048
049 PolynomialList<BigRational> m;
050 PolynomialList<BigRational> p;
051
052 GenPolynomial<BigRational> a;
053 GenPolynomial<BigRational> b;
054 GenPolynomial<BigRational> c;
055 GenPolynomial<BigRational> d;
056 GenPolynomial<BigRational> e;
057
058 int rl = 4;
059 int kl = 4;
060 int ll = 4;
061 int el = 5;
062 float q = 0.5f;
063
064 protected void setUp() {
065 a = b = c = d = e = null;
066 m = null;
067 p = null;
068 BigRational coeff = new BigRational(9);
069 fac = new GenPolynomialRing<BigRational>(coeff,rl);
070 }
071
072 protected void tearDown() {
073 a = b = c = d = e = null;
074 m = null;
075 p = null;
076 }
077
078
079 /**
080 * Test constructor and toString.
081 *
082 */
083 public void testConstructor() {
084 p = new PolynomialList<BigRational>(fac,(List<GenPolynomial<BigRational>>)null);
085 assertTrue("p = 0", p.list == null);
086
087 m = new PolynomialList<BigRational>(fac,
088 new ArrayList<GenPolynomial<BigRational>>());
089 assertTrue("m = 0", m.list != null);
090 assertTrue("m.size() == 0", m.list.size() == 0 );
091 }
092
093
094 /**
095 * Test polynomial list.
096 *
097 */
098 public void testPolynomialList() {
099 List<GenPolynomial<BigRational>> l = new ArrayList<GenPolynomial<BigRational>>();
100 for (int i = 0; i < 7; i++) {
101 a = fac.random(ll+i); // rl, el, q );
102 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
103 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
104 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
105 l.add( a );
106 }
107 p = new PolynomialList<BigRational>(fac,l);
108 //System.out.println("p = "+p);
109
110 assertTrue("p == p", p.equals(p) );
111 assertEquals("p.length", 7, p.list.size() );
112 }
113
114
115 /**
116 * Test ordered polynomial list.
117 *
118 */
119 public void testOrderedPolynomialList() {
120 List<GenPolynomial<BigRational>> l = new ArrayList<GenPolynomial<BigRational>>();
121 for (int i = 0; i < 7; i++) {
122 a = fac.random(ll+i); // rl, el, q );
123 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0);
124 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() );
125 assertTrue(" not isONE( a"+i+" )", !a.isONE() );
126 l.add( a );
127 }
128 p = new PolynomialList<BigRational>(fac,l);
129 //System.out.println("p = "+p);
130
131 m = new OrderedPolynomialList<BigRational>(fac,p.list);
132 //System.out.println("m = "+m);
133
134 assertTrue("p == m", p.equals(m) );
135 assertTrue("m != p", !m.equals(p) );
136 assertEquals("p.length", 7, p.list.size() );
137 assertEquals("m.length", 7, m.list.size() );
138 }
139
140
141
142 }