001/* 002 * $Id: GBFactoryTest.java 5863 2018-07-20 11:13:34Z kredel $ 003 */ 004 005package edu.jas.gbufd; 006 007 008 009import edu.jas.arith.BigComplex; 010import edu.jas.arith.BigInteger; 011import edu.jas.arith.BigRational; 012import edu.jas.arith.ModInteger; 013import edu.jas.arith.ModIntegerRing; 014import edu.jas.arith.Product; 015import edu.jas.arith.ProductRing; 016import edu.jas.gb.GBProxy; 017import edu.jas.gb.GroebnerBase; 018import edu.jas.gb.GroebnerBaseAbstract; 019import edu.jas.gb.GroebnerBaseSeq; 020import edu.jas.kern.ComputerThreads; 021import edu.jas.poly.AlgebraicNumber; 022import edu.jas.poly.AlgebraicNumberRing; 023import edu.jas.poly.GenPolynomial; 024import edu.jas.poly.GenPolynomialRing; 025import edu.jas.poly.TermOrder; 026import edu.jas.structure.RingFactory; 027 028// import java.util.Map; 029 030import junit.framework.Test; 031import junit.framework.TestCase; 032import junit.framework.TestSuite; 033 034 035/** 036 * Groebner base factory tests with JUnit. 037 * @author Heinz Kredel 038 */ 039 040public class GBFactoryTest extends TestCase { 041 042 043 /** 044 * main. 045 */ 046 public static void main(String[] args) { 047 junit.textui.TestRunner.run(suite()); 048 ComputerThreads.terminate(); 049 } 050 051 052 /** 053 * Constructs a <CODE>GBFactoryTest</CODE> object. 054 * @param name String. 055 */ 056 public GBFactoryTest(String name) { 057 super(name); 058 } 059 060 061 /** 062 */ 063 public static Test suite() { 064 TestSuite suite = new TestSuite(GBFactoryTest.class); 065 return suite; 066 } 067 068 069 //private final static int bitlen = 100; 070 071 TermOrder to = new TermOrder(TermOrder.INVLEX); 072 073 074 GenPolynomialRing<BigInteger> dfac; 075 076 077 GenPolynomialRing<BigInteger> cfac; 078 079 080 GenPolynomialRing<GenPolynomial<BigInteger>> rfac; 081 082 083 BigInteger ai, bi, ci, di, ei; 084 085 086 GenPolynomial<BigInteger> a, b, c, d, e; 087 088 089 GenPolynomial<GenPolynomial<BigInteger>> ar, br, cr, dr, er; 090 091 092 int rl = 5; 093 094 095 int kl = 4; 096 097 098 int ll = 5; 099 100 101 int el = 3; 102 103 104 float q = 0.3f; 105 106 107 @Override 108 protected void setUp() { 109 a = b = c = d = e = null; 110 ai = bi = ci = di = ei = null; 111 ar = br = cr = dr = er = null; 112 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl, to); 113 cfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl - 1, to); 114 rfac = new GenPolynomialRing<GenPolynomial<BigInteger>>(cfac, 1, to); 115 } 116 117 118 @Override 119 protected void tearDown() { 120 a = b = c = d = e = null; 121 ai = bi = ci = di = ei = null; 122 ar = br = cr = dr = er = null; 123 dfac = null; 124 cfac = null; 125 rfac = null; 126 } 127 128 129 /** 130 * Test get BigInteger implementation. 131 */ 132 public void testBigInteger() { 133 BigInteger bi = new BigInteger(); 134 GroebnerBase<BigInteger> bba; 135 136 bba = GBFactory.getImplementation(bi); 137 //System.out.println("bba = " + bba); 138 assertTrue("bba integer " + bba, bba instanceof GroebnerBasePseudoSeq); 139 } 140 141 142 /** 143 * Test get ModInteger implementation. 144 */ 145 public void testModInteger() { 146 ModIntegerRing mi = new ModIntegerRing(19, true); 147 GroebnerBase<ModInteger> bba; 148 149 bba = GBFactory.getImplementation(mi); 150 //System.out.println("bba = " + bba); 151 assertTrue("bba modular field " + bba, bba instanceof GroebnerBaseSeq); 152 153 mi = new ModIntegerRing(30); 154 bba = GBFactory.getImplementation(mi); 155 //System.out.println("bba = " + bba); 156 assertTrue("bba modular ring " + bba, bba instanceof GroebnerBasePseudoSeq); 157 } 158 159 160 /** 161 * Test get BigRational implementation. 162 */ 163 public void testBigRational() { 164 BigRational b = new BigRational(); 165 GroebnerBase<BigRational> bba; 166 167 bba = GBFactory.getImplementation(b); 168 //System.out.println("bba = " + bba); 169 assertTrue("bba field " + bba, bba instanceof GroebnerBaseSeq); 170 } 171 172 173 /** 174 * Test get BigComplex implementation. 175 */ 176 public void testBigComplex() { 177 BigComplex b = new BigComplex(); 178 GroebnerBase<BigComplex> bba; 179 180 bba = GBFactory.<BigComplex> getImplementation(b); 181 //System.out.println("bba = " + bba); 182 assertTrue("bba field " + bba, bba instanceof GroebnerBaseSeq); 183 } 184 185 186 /** 187 * Test get AlgebraicNumber<BigRational> implementation. 188 */ 189 public void testAlgebraicNumberBigRational() { 190 BigRational b = new BigRational(); 191 GenPolynomialRing<BigRational> fac; 192 fac = new GenPolynomialRing<BigRational>(b, 1); 193 GenPolynomial<BigRational> mo = fac.random(kl, ll, el, q); 194 while (mo.isZERO() || mo.isONE() || mo.isConstant()) { 195 mo = fac.random(kl, ll, el, q); 196 } 197 198 AlgebraicNumberRing<BigRational> afac; 199 afac = new AlgebraicNumberRing<BigRational>(mo); 200 201 GroebnerBase<AlgebraicNumber<BigRational>> bba; 202 203 bba = GBFactory.<AlgebraicNumber<BigRational>> getImplementation(afac); 204 //System.out.println("bba1 = " + bba); 205 assertTrue("bba algebraic ring " + bba, bba instanceof GroebnerBasePseudoSeq); 206 207 mo = fac.univariate(0).subtract(fac.getONE()); 208 afac = new AlgebraicNumberRing<BigRational>(mo, true); 209 210 bba = GBFactory.<AlgebraicNumber<BigRational>> getImplementation(afac); 211 //System.out.println("bba1 = " + bba); 212 assertTrue("bba algebraic field " + bba, bba instanceof GroebnerBaseSeq); 213 } 214 215 216 /** 217 * Test get AlgebraicNumber<ModInteger> implementation. 218 */ 219 public void testAlgebraicNumberModInteger() { 220 ModIntegerRing b = new ModIntegerRing(19, true); 221 GenPolynomialRing<ModInteger> fac; 222 fac = new GenPolynomialRing<ModInteger>(b, 1); 223 GenPolynomial<ModInteger> mo = fac.random(kl, ll, el, q); 224 while (mo.isZERO() || mo.isONE() || mo.isConstant()) { 225 mo = fac.random(kl, ll, el, q); 226 } 227 228 AlgebraicNumberRing<ModInteger> afac; 229 afac = new AlgebraicNumberRing<ModInteger>(mo); 230 231 AlgebraicNumber<ModInteger> a = afac.getONE(); 232 assertTrue("a == 1 " + a, a.isONE()); 233 GroebnerBase<AlgebraicNumber<ModInteger>> bba; 234 235 bba = GBFactory.<AlgebraicNumber<ModInteger>> getImplementation(afac); 236 //System.out.println("bba2 = " + bba); 237 assertTrue("bba algebraic ring " + bba, bba instanceof GroebnerBasePseudoSeq); 238 } 239 240 241 /** 242 * Test get GenPolynomial implementation. 243 */ 244 @SuppressWarnings("unchecked") 245 public void testGenPolynomial() { 246 BigRational b = new BigRational(); 247 GenPolynomialRing<BigRational> fac; 248 fac = new GenPolynomialRing<BigRational>(b, rl, to); 249 RingFactory<GenPolynomial<BigRational>> rf = fac; 250 251 GroebnerBase<GenPolynomial<BigRational>> bba; 252 253 bba = GBFactory.getImplementation(fac); 254 //System.out.println("bba = " + bba); 255 assertTrue("bba recursive polynomial " + bba, bba instanceof GroebnerBasePseudoRecSeq); 256 257 GroebnerBase<BigRational> bb; 258 bb = GBFactory.<BigRational> getImplementation((RingFactory) rf); 259 //System.out.println("bb = " + bb); 260 assertTrue("bba recursive polynomial " + bb, bb instanceof GroebnerBasePseudoRecSeq); 261 } 262 263 264 /** 265 * Test get Product implementation. 266 */ 267 @SuppressWarnings({ "unchecked" }) 268 public void testProduct() { 269 ModIntegerRing mi = new ModIntegerRing(19, true); 270 ProductRing<ModInteger> fac; 271 fac = new ProductRing<ModInteger>(mi, 3); 272 RingFactory<Product<ModInteger>> rf = fac; 273 274 GroebnerBase<Product<ModInteger>> bba; 275 276 bba = GBFactory.getImplementation(fac); 277 //System.out.println("bba = " + bba); 278 assertTrue("bba product " + bba, bba instanceof RGroebnerBaseSeq); 279 280 mi = new ModIntegerRing(30); 281 fac = new ProductRing<ModInteger>(mi, 3); 282 rf = fac; 283 284 GroebnerBase<Product<ModInteger>> bb; 285 bb = GBFactory.<Product<ModInteger>> getImplementation((RingFactory) rf); 286 //System.out.println("bb = " + bb); 287 assertTrue("bba product " + bb, bb instanceof RGroebnerBasePseudoSeq); 288 } 289 290 291 /** 292 * Test get proxy implementation. 293 */ 294 public void testProxy() { 295 BigRational b = new BigRational(); 296 GroebnerBaseAbstract<BigRational> bba; 297 298 bba = GBFactory.getProxy(b); 299 //System.out.println("bba = " + bba); 300 assertTrue("bba field " + bba, bba instanceof GBProxy); 301 bba.terminate(); 302 303 304 ModIntegerRing m = new ModIntegerRing(2 * 3); 305 GroebnerBaseAbstract<ModInteger> bbm; 306 307 bbm = GBFactory.getProxy(m); 308 //System.out.println("bba = " + bba); 309 assertTrue("bbm ! field " + bbm, !(bbm instanceof GBProxy)); 310 bbm.terminate(); 311 } 312 313}