001/* 002 * $Id: ModGroebnerBaseTest.java 5268 2015-07-27 18:05:58Z kredel $ 003 */ 004 005package edu.jas.gb; 006 007 008import java.util.ArrayList; 009import java.util.List; 010 011import junit.framework.Test; 012import junit.framework.TestCase; 013import junit.framework.TestSuite; 014 015import org.apache.log4j.BasicConfigurator; 016// import org.apache.log4j.Logger; 017 018// import edu.jas.structure.RingElem; 019import edu.jas.arith.BigRational; 020import edu.jas.kern.ComputerThreads; 021import edu.jas.poly.GenPolynomial; 022import edu.jas.poly.GenPolynomialRing; 023import edu.jas.poly.ModuleList; 024import edu.jas.poly.PolynomialList; 025import edu.jas.poly.TermOrder; 026 027 028/** 029 * ModGroebnerBase sequential and parallel tests with JUnit. 030 * @author Heinz Kredel. 031 */ 032 033public class ModGroebnerBaseTest extends TestCase { 034 035 036 //private static final Logger logger = Logger.getLogger(ModGroebnerBaseTest.class); 037 038 /** 039 * main. 040 */ 041 public static void main(String[] args) { 042 BasicConfigurator.configure(); 043 junit.textui.TestRunner.run(suite()); 044 ComputerThreads.terminate(); 045 } 046 047 048 /** 049 * Constructs a <CODE>ModGroebnerBaseTest</CODE> object. 050 * @param name String. 051 */ 052 public ModGroebnerBaseTest(String name) { 053 super(name); 054 } 055 056 057 /** 058 * suite. 059 */ 060 public static Test suite() { 061 TestSuite suite = new TestSuite(ModGroebnerBaseTest.class); 062 return suite; 063 } 064 065 066 GenPolynomialRing<BigRational> fac; 067 068 069 PolynomialList<BigRational> F; 070 071 072 List<GenPolynomial<BigRational>> G; 073 074 075 GenPolynomial<BigRational> a, b, c, d, e; 076 077 078 TermOrder tord; 079 080 081 List<List<GenPolynomial<BigRational>>> L; 082 083 084 List<GenPolynomial<BigRational>> V; 085 086 087 ModuleList<BigRational> M, N; 088 089 090 GroebnerBaseAbstract<BigRational> mbb; 091 092 093 int rl = 3; //4; //3; 094 095 096 int kl = 7; 097 098 099 int ll = 5; 100 101 102 int el = 2; 103 104 105 float q = 0.2f; //0.4f 106 107 108 BigRational coeff; 109 110 111 @Override 112 protected void setUp() { 113 coeff = new BigRational(); 114 tord = new TermOrder(); 115 fac = new GenPolynomialRing<BigRational>(coeff, rl, tord); 116 mbb = new GroebnerBaseSeq<BigRational>(); //coeff); 117 a = b = c = d = e = null; 118 119 do { 120 a = fac.random(kl, ll, el, q); 121 b = fac.random(kl, ll, el, q); 122 c = fac.random(kl, ll, el, q); 123 d = fac.random(kl, ll, el, q); 124 } while (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()); 125 e = d; //fac.random(kl, ll, el, q ); 126 } 127 128 129 @Override 130 protected void tearDown() { 131 mbb.terminate(); 132 mbb = null; 133 a = b = c = d = e = null; 134 fac = null; 135 tord = null; 136 } 137 138 139 /** 140 * Test sequential GBase. 141 */ 142 public void testSequentialModGB() { 143 L = new ArrayList<List<GenPolynomial<BigRational>>>(); 144 145 V = new ArrayList<GenPolynomial<BigRational>>(); 146 V.add(a); 147 V.add(fac.getZERO()); 148 V.add(fac.getONE()); 149 L.add(V); 150 M = new ModuleList<BigRational>(fac, L); 151 assertTrue("isGB( { (a,0,1) } )", mbb.isGB(M)); 152 153 N = mbb.GB(M); 154 assertTrue("is( { (a,0,1) } )", mbb.isGB(N)); 155 156 V = new ArrayList<GenPolynomial<BigRational>>(); 157 V.add(b); 158 V.add(fac.getONE()); 159 V.add(fac.getZERO()); 160 L.add(V); 161 M = new ModuleList<BigRational>(fac, L); 162 //System.out.println("L = " + L.size() ); 163 164 N = mbb.GB(M); 165 assertTrue("isGB( { (a,0,1),(b,1,0) } )", mbb.isGB(N)); 166 //System.out.println("N = " + N ); 167 168 V = new ArrayList<GenPolynomial<BigRational>>(); 169 V.add(c); 170 V.add(fac.getZERO()); 171 V.add(fac.getZERO()); 172 L.add(V); 173 M = new ModuleList<BigRational>(fac, L); 174 //System.out.println("L = " + L.size() ); 175 176 N = mbb.GB(M); 177 assertTrue("isGB( { (a,),(b,),(c,) } )", mbb.isGB(N)); 178 //System.out.println("N = " + N ); 179 180 V = new ArrayList<GenPolynomial<BigRational>>(); 181 V.add(d); 182 V.add(fac.getZERO()); 183 V.add(fac.getZERO()); 184 L.add(V); 185 M = new ModuleList<BigRational>(fac, L); 186 //System.out.println("L = " + L.size() ); 187 188 N = mbb.GB(M); 189 assertTrue("isGB( { (a,b,c,d) } )", mbb.isGB(N)); 190 //System.out.println("N = " + N ); 191 } 192 193 194 /** 195 * Test parallel GBase. 196 */ 197 public void testParallelModGB() { 198 mbb = new GroebnerBaseParallel<BigRational>(); //coeff); 199 200 L = new ArrayList<List<GenPolynomial<BigRational>>>(); 201 202 V = new ArrayList<GenPolynomial<BigRational>>(); 203 V.add(a); 204 V.add(fac.getZERO()); 205 V.add(fac.getONE()); 206 L.add(V); 207 M = new ModuleList<BigRational>(fac, L); 208 assertTrue("isGB( { (a,0,1) } )", mbb.isGB(M)); 209 210 N = mbb.GB(M); 211 assertTrue("is( { (a,0,1) } )", mbb.isGB(N)); 212 213 V = new ArrayList<GenPolynomial<BigRational>>(); 214 V.add(b); 215 V.add(fac.getONE()); 216 V.add(fac.getZERO()); 217 L.add(V); 218 M = new ModuleList<BigRational>(fac, L); 219 //System.out.println("L = " + L.size() ); 220 221 N = mbb.GB(M); 222 assertTrue("isGB( { (a,0,1),(b,1,0) } )", mbb.isGB(N)); 223 //System.out.println("N = " + N ); 224 225 V = new ArrayList<GenPolynomial<BigRational>>(); 226 V.add(c); 227 V.add(fac.getZERO()); 228 V.add(fac.getZERO()); 229 L.add(V); 230 M = new ModuleList<BigRational>(fac, L); 231 //System.out.println("L = " + L.size() ); 232 233 N = mbb.GB(M); 234 assertTrue("isGB( { (a,),(b,),(c,) } )", mbb.isGB(N)); 235 //System.out.println("N = " + N ); 236 237 V = new ArrayList<GenPolynomial<BigRational>>(); 238 V.add(d); 239 V.add(fac.getZERO()); 240 V.add(fac.getZERO()); 241 L.add(V); 242 M = new ModuleList<BigRational>(fac, L); 243 //System.out.println("L = " + L.size() ); 244 245 N = mbb.GB(M); 246 assertTrue("isGB( { (a,b,c,d) } )", mbb.isGB(N)); 247 //System.out.println("N = " + N ); 248 } 249 250}