001/* 002 * $Id$ 003 */ 004 005package edu.jas.poly; 006 007 008import java.util.ArrayList; 009import java.util.List; 010 011import edu.jas.arith.BigRational; 012 013import junit.framework.Test; 014import junit.framework.TestCase; 015import junit.framework.TestSuite; 016 017 018/** 019 * PolynomialList Test using JUnit. 020 * @author Heinz Kredel 021 */ 022 023public class PolynomialListTest extends TestCase { 024 025 026 /** 027 * main. 028 */ 029 public static void main(String[] args) { 030 junit.textui.TestRunner.run(suite()); 031 } 032 033 034 /** 035 * Constructs a <CODE>PolynomialListTest</CODE> object. 036 * @param name String. 037 */ 038 public PolynomialListTest(String name) { 039 super(name); 040 } 041 042 043 /** 044 */ 045 public static Test suite() { 046 TestSuite suite = new TestSuite(PolynomialListTest.class); 047 return suite; 048 } 049 050 GenPolynomialRing<BigRational> fac; 051 052 053 PolynomialList<BigRational> m; 054 055 056 PolynomialList<BigRational> p; 057 058 059 GenPolynomial<BigRational> a, b, c, d, e; 060 061 062 int rl = 4; 063 064 065 int kl = 4; 066 067 068 int ll = 4; 069 070 071 int el = 5; 072 073 074 float q = 0.5f; 075 076 077 @Override 078 protected void setUp() { 079 a = b = c = d = e = null; 080 m = null; 081 p = null; 082 BigRational coeff = new BigRational(9); 083 fac = new GenPolynomialRing<BigRational>(coeff, rl); 084 } 085 086 087 @Override 088 protected void tearDown() { 089 a = b = c = d = e = null; 090 m = null; 091 p = null; 092 } 093 094 095 /** 096 * Test constructor and toString. 097 */ 098 public void testConstructor() { 099 p = new PolynomialList<BigRational>(fac, (List<GenPolynomial<BigRational>>) null); 100 assertTrue("p = 0", p.list == null); 101 102 m = new PolynomialList<BigRational>(fac, new ArrayList<GenPolynomial<BigRational>>()); 103 assertTrue("m = 0", m.list != null); 104 assertTrue("m.size() == 0", m.list.size() == 0); 105 106 String s = m.toScript(); 107 //System.out.println("m.toScript: " + s + ", " + s.length()); 108 assertEquals("#s == 60: " + s, s.length(), 60); 109 } 110 111 112 /** 113 * Test polynomial list. 114 */ 115 public void testPolynomialList() { 116 List<GenPolynomial<BigRational>> l = new ArrayList<GenPolynomial<BigRational>>(); 117 for (int i = 0; i < 7; i++) { 118 a = fac.random(ll + i); 119 assertTrue("length( a" + i + " ) <> 0", a.length() >= 0); 120 assertTrue(" not isZERO( a" + i + " )", !a.isZERO()); 121 assertTrue(" not isONE( a" + i + " )", !a.isONE()); 122 l.add(a); 123 } 124 p = new PolynomialList<BigRational>(fac, l); 125 //System.out.println("p = "+p); 126 127 assertTrue("p == p", p.equals(p)); 128 assertEquals("p.length", 7, p.list.size()); 129 } 130 131 132 /** 133 * Test ordered polynomial list. 134 */ 135 public void testOrderedPolynomialList() { 136 List<GenPolynomial<BigRational>> l = new ArrayList<GenPolynomial<BigRational>>(); 137 for (int i = 0; i < 7; i++) { 138 a = fac.random(ll + i); 139 assertTrue("length( a" + i + " ) <> 0", a.length() >= 0); 140 assertTrue(" not isZERO( a" + i + " )", !a.isZERO()); 141 assertTrue(" not isONE( a" + i + " )", !a.isONE()); 142 l.add(a); 143 } 144 p = new PolynomialList<BigRational>(fac, l); 145 //System.out.println("p = "+p); 146 147 m = new OrderedPolynomialList<BigRational>(fac, p.list); 148 //System.out.println("m = "+m); 149 150 assertTrue("p == m", p.equals(m)); 151 assertTrue("m != p", !m.equals(p)); 152 assertEquals("p.length", 7, p.list.size()); 153 assertEquals("m.length", 7, m.list.size()); 154 } 155 156 157 /** 158 * Test homogeneous polynomial list. 159 */ 160 public void testHomogeneousPolynomialList() { 161 List<GenPolynomial<BigRational>> l = new ArrayList<GenPolynomial<BigRational>>(); 162 for (int i = 0; i < 7; i++) { 163 a = fac.random(ll + i); 164 assertTrue("length( a" + i + " ) <> 0", a.length() >= 0); 165 assertTrue(" not isZERO( a" + i + " )", !a.isZERO()); 166 assertTrue(" not isONE( a" + i + " )", !a.isONE()); 167 l.add(a); 168 } 169 p = new PolynomialList<BigRational>(fac, l); 170 //System.out.println("p = "+p); 171 172 PolynomialList<BigRational> h = p.homogenize(); 173 //System.out.println("h = "+h); 174 assertTrue("h is homogen", h.isHomogeneous()); 175 176 PolynomialList<BigRational> pp = h.deHomogenize(); 177 //System.out.println("pp = "+pp); 178 assertTrue("p == pp", p.equals(pp)); 179 } 180 181}