001/* 002 * $Id: PolynomialListTest.java 3814 2011-10-29 11:56:29Z kredel $ 003 */ 004 005package edu.jas.poly; 006 007import java.util.ArrayList; 008import java.util.List; 009 010import junit.framework.Test; 011import junit.framework.TestCase; 012import junit.framework.TestSuite; 013import edu.jas.arith.BigRational; 014 015 016/** 017 * PolynomialList Test using JUnit. 018 * @author Heinz Kredel 019 */ 020 021public 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 /** 032 * Constructs a <CODE>PolynomialListTest</CODE> object. 033 * @param name String. 034 */ 035 public PolynomialListTest(String name) { 036 super(name); 037 } 038 039 040 /** 041 */ 042 public static Test suite() { 043 TestSuite suite= new TestSuite(PolynomialListTest.class); 044 return suite; 045 } 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 065 protected void setUp() { 066 a = b = c = d = e = null; 067 m = null; 068 p = null; 069 BigRational coeff = new BigRational(9); 070 fac = new GenPolynomialRing<BigRational>(coeff,rl); 071 } 072 073 074 protected void tearDown() { 075 a = b = c = d = e = null; 076 m = null; 077 p = null; 078 } 079 080 081 /** 082 * Test constructor and toString. 083 */ 084 public void testConstructor() { 085 p = new PolynomialList<BigRational>(fac,(List<GenPolynomial<BigRational>>)null); 086 assertTrue("p = 0", p.list == null); 087 088 m = new PolynomialList<BigRational>(fac, 089 new ArrayList<GenPolynomial<BigRational>>()); 090 assertTrue("m = 0", m.list != null); 091 assertTrue("m.size() == 0", m.list.size() == 0 ); 092 } 093 094 095 /** 096 * Test polynomial list. 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 public void testOrderedPolynomialList() { 119 List<GenPolynomial<BigRational>> l = new ArrayList<GenPolynomial<BigRational>>(); 120 for (int i = 0; i < 7; i++) { 121 a = fac.random(ll+i); // rl, el, q ); 122 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0); 123 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() ); 124 assertTrue(" not isONE( a"+i+" )", !a.isONE() ); 125 l.add( a ); 126 } 127 p = new PolynomialList<BigRational>(fac,l); 128 //System.out.println("p = "+p); 129 130 m = new OrderedPolynomialList<BigRational>(fac,p.list); 131 //System.out.println("m = "+m); 132 133 assertTrue("p == m", p.equals(m) ); 134 assertTrue("m != p", !m.equals(p) ); 135 assertEquals("p.length", 7, p.list.size() ); 136 assertEquals("m.length", 7, m.list.size() ); 137 } 138 139 140 /** 141 * Test homogeneous polynomial list. 142 */ 143 public void testHomogeneousPolynomialList() { 144 List<GenPolynomial<BigRational>> l = new ArrayList<GenPolynomial<BigRational>>(); 145 for (int i = 0; i < 7; i++) { 146 a = fac.random(ll+i); // rl, el, q ); 147 assertTrue("length( a"+i+" ) <> 0", a.length() >= 0); 148 assertTrue(" not isZERO( a"+i+" )", !a.isZERO() ); 149 assertTrue(" not isONE( a"+i+" )", !a.isONE() ); 150 l.add( a ); 151 } 152 p = new PolynomialList<BigRational>(fac,l); 153 //System.out.println("p = "+p); 154 155 PolynomialList<BigRational> h = p.homogenize(); 156 //System.out.println("h = "+h); 157 assertTrue("h is homogen", h.isHomogeneous() ); 158 159 PolynomialList<BigRational> pp = h.deHomogenize(); 160 //System.out.println("pp = "+pp); 161 assertTrue("p == pp", p.equals(pp) ); 162 } 163 164}