001 /* 002 * $Id: ModGroebnerBaseTest.java 3445 2010-12-25 17:24:04Z kredel $ 003 */ 004 005 package edu.jas.gbmod; 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 org.apache.log4j.BasicConfigurator; 015 //import org.apache.log4j.Logger; 016 017 018 //import edu.jas.structure.RingElem; 019 020 import edu.jas.arith.BigRational; 021 022 import edu.jas.poly.GenPolynomial; 023 import edu.jas.poly.GenPolynomialRing; 024 import edu.jas.poly.ModuleList; 025 import edu.jas.poly.PolynomialList; 026 import edu.jas.poly.TermOrder; 027 028 029 030 /** 031 * ModGroebnerBase tests with JUnit. 032 * @author Heinz Kredel. 033 */ 034 035 public class ModGroebnerBaseTest extends TestCase { 036 037 //private static final Logger logger = Logger.getLogger(ModGroebnerBaseTest.class); 038 039 /** 040 * main. 041 */ 042 public static void main (String[] args) { 043 BasicConfigurator.configure(); 044 junit.textui.TestRunner.run( suite() ); 045 } 046 047 /** 048 * Constructs a <CODE>ModGroebnerBaseTest</CODE> object. 049 * @param name String. 050 */ 051 public ModGroebnerBaseTest(String name) { 052 super(name); 053 } 054 055 /** 056 * suite. 057 */ 058 public static Test suite() { 059 TestSuite suite= new TestSuite(ModGroebnerBaseTest.class); 060 return suite; 061 } 062 063 GenPolynomialRing<BigRational> fac; 064 065 PolynomialList<BigRational> F; 066 List<GenPolynomial<BigRational>> G; 067 068 GenPolynomial<BigRational> a; 069 GenPolynomial<BigRational> b; 070 GenPolynomial<BigRational> c; 071 GenPolynomial<BigRational> d; 072 GenPolynomial<BigRational> e; 073 074 TermOrder tord; 075 076 List<List<GenPolynomial<BigRational>>> L; 077 List<GenPolynomial<BigRational>> V; 078 ModuleList<BigRational> M; 079 ModuleList<BigRational> N; 080 081 ModGroebnerBase<BigRational> mbb; 082 083 int rl = 3; //4; //3; 084 int kl = 8; 085 int ll = 5; 086 int el = 2; 087 float q = 0.2f; //0.4f 088 089 protected void setUp() { 090 BigRational coeff = new BigRational(9); 091 tord = new TermOrder(); 092 fac = new GenPolynomialRing<BigRational>(coeff,rl,tord); 093 mbb = new ModGroebnerBaseAbstract<BigRational>(coeff); 094 a = b = c = d = e = null; 095 096 do { 097 a = fac.random(kl, ll, el, q ); 098 b = fac.random(kl, ll, el, q ); 099 c = fac.random(kl, ll, el, q ); 100 d = fac.random(kl, ll, el, q ); 101 } while ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ); 102 e = d; //fac.random(kl, ll, el, q ); 103 } 104 105 protected void tearDown() { 106 mbb = null; 107 a = b = c = d = e = null; 108 fac = null; 109 tord = null; 110 } 111 112 113 /** 114 * Test sequential GBase. 115 * 116 */ 117 public void testSequentialModGB() { 118 119 L = new ArrayList<List<GenPolynomial<BigRational>>>(); 120 121 assertTrue("not isZERO( a )", !a.isZERO() ); 122 V = new ArrayList<GenPolynomial<BigRational>>(); 123 V.add(a); V.add(fac.getZERO()); V.add(fac.getONE()); 124 L.add(V); 125 M = new ModuleList<BigRational>(fac,L); 126 assertTrue("isGB( { (a,0,1) } )", mbb.isGB(M) ); 127 128 N = mbb.GB( M ); 129 assertTrue("isGB( { (a,0,1) } )", mbb.isGB(N) ); 130 131 assertTrue("not isZERO( b )", !b.isZERO() ); 132 V = new ArrayList<GenPolynomial<BigRational>>(); 133 V.add(b); V.add(fac.getONE()); V.add(fac.getZERO()); 134 L.add(V); 135 M = new ModuleList<BigRational>(fac,L); 136 //System.out.println("L = " + L.size() ); 137 138 N = mbb.GB( M ); 139 assertTrue("isDIRPGB( { (a,0,1),(b,1,0) } )", mbb.isGB(N) ); 140 //System.out.println("N = " + N ); 141 142 assertTrue("not isZERO( c )", !c.isZERO() ); 143 V = new ArrayList<GenPolynomial<BigRational>>(); 144 V.add(c); V.add(fac.getZERO()); V.add(fac.getZERO()); 145 L.add(V); 146 M = new ModuleList<BigRational>(fac,L); 147 //System.out.println("L = " + L.size() ); 148 149 N = mbb.GB( M ); 150 assertTrue("isDIRPGB( { (a,),(b,),(c,) } )", mbb.isGB(N) ); 151 //System.out.println("N = " + N ); 152 153 assertTrue("not isZERO( d )", !d.isZERO() ); 154 V = new ArrayList<GenPolynomial<BigRational>>(); 155 V.add(d); V.add(fac.getZERO()); V.add(fac.getZERO()); 156 L.add(V); 157 M = new ModuleList<BigRational>(fac,L); 158 //System.out.println("L = " + L.size() ); 159 160 N = mbb.GB( M ); 161 assertTrue("isDIRPGB( { (a,b,c,d) } )", mbb.isGB(N) ); 162 //System.out.println("N = " + N ); 163 164 } 165 166 }