001 /* 002 * $Id: GBFactoryTest.java 3432 2010-12-24 14:28:19Z kredel $ 003 */ 004 005 package edu.jas.gbufd; 006 007 008 //import java.util.Map; 009 010 import junit.framework.Test; 011 import junit.framework.TestCase; 012 import junit.framework.TestSuite; 013 014 import org.apache.log4j.BasicConfigurator; 015 016 import edu.jas.arith.BigComplex; 017 import edu.jas.arith.BigInteger; 018 import edu.jas.arith.BigRational; 019 import edu.jas.arith.ModInteger; 020 import edu.jas.arith.ModIntegerRing; 021 import edu.jas.arith.Product; 022 import edu.jas.arith.ProductRing; 023 import edu.jas.gb.GBProxy; 024 import edu.jas.gb.GroebnerBase; 025 import edu.jas.gb.GroebnerBaseAbstract; 026 import edu.jas.gb.GroebnerBaseSeq; 027 import edu.jas.poly.AlgebraicNumber; 028 import edu.jas.poly.AlgebraicNumberRing; 029 import edu.jas.poly.GenPolynomial; 030 import edu.jas.poly.GenPolynomialRing; 031 import edu.jas.poly.TermOrder; 032 import edu.jas.structure.RingFactory; 033 034 035 /** 036 * GreatestCommonDivisor factory tests with JUnit. 037 * @author Heinz Kredel. 038 */ 039 040 public class GBFactoryTest extends TestCase { 041 042 043 /** 044 * main. 045 */ 046 public static void main(String[] args) { 047 BasicConfigurator.configure(); 048 junit.textui.TestRunner.run(suite()); 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; 084 085 086 BigInteger bi; 087 088 089 BigInteger ci; 090 091 092 BigInteger di; 093 094 095 BigInteger ei; 096 097 098 GenPolynomial<BigInteger> a; 099 100 101 GenPolynomial<BigInteger> b; 102 103 104 GenPolynomial<BigInteger> c; 105 106 107 GenPolynomial<BigInteger> d; 108 109 110 GenPolynomial<BigInteger> e; 111 112 113 GenPolynomial<GenPolynomial<BigInteger>> ar; 114 115 116 GenPolynomial<GenPolynomial<BigInteger>> br; 117 118 119 GenPolynomial<GenPolynomial<BigInteger>> cr; 120 121 122 GenPolynomial<GenPolynomial<BigInteger>> dr; 123 124 125 GenPolynomial<GenPolynomial<BigInteger>> er; 126 127 128 int rl = 5; 129 130 131 int kl = 4; 132 133 134 int ll = 5; 135 136 137 int el = 3; 138 139 140 float q = 0.3f; 141 142 143 @Override 144 protected void setUp() { 145 a = b = c = d = e = null; 146 ai = bi = ci = di = ei = null; 147 ar = br = cr = dr = er = null; 148 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl, to); 149 cfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl - 1, to); 150 rfac = new GenPolynomialRing<GenPolynomial<BigInteger>>(cfac, 1, to); 151 } 152 153 154 @Override 155 protected void tearDown() { 156 a = b = c = d = e = null; 157 ai = bi = ci = di = ei = null; 158 ar = br = cr = dr = er = null; 159 dfac = null; 160 cfac = null; 161 rfac = null; 162 } 163 164 165 /** 166 * Test get BigInteger implementation. 167 * 168 */ 169 public void testBigInteger() { 170 BigInteger bi = new BigInteger(); 171 GroebnerBase<BigInteger> bba; 172 173 bba = GBFactory.getImplementation(bi); 174 //System.out.println("bba = " + bba); 175 assertTrue("bba integer " + bba, bba instanceof GroebnerBasePseudoSeq); 176 } 177 178 179 /** 180 * Test get ModInteger implementation. 181 * 182 */ 183 public void testModInteger() { 184 ModIntegerRing mi = new ModIntegerRing(19, true); 185 GroebnerBase<ModInteger> bba; 186 187 bba = GBFactory.getImplementation(mi); 188 //System.out.println("bba = " + bba); 189 assertTrue("bba modular field " + bba, bba instanceof GroebnerBaseSeq); 190 191 mi = new ModIntegerRing(30); 192 bba = GBFactory.getImplementation(mi); 193 //System.out.println("bba = " + bba); 194 assertTrue("bba modular ring " + bba, bba instanceof GroebnerBasePseudoSeq); 195 } 196 197 198 /** 199 * Test get BigRational implementation. 200 * 201 */ 202 public void testBigRational() { 203 BigRational b = new BigRational(); 204 GroebnerBase<BigRational> bba; 205 206 bba = GBFactory.getImplementation(b); 207 //System.out.println("bba = " + bba); 208 assertTrue("bba field " + bba, bba instanceof GroebnerBaseSeq); 209 } 210 211 212 /** 213 * Test get BigComplex implementation. 214 * 215 */ 216 public void testBigComplex() { 217 BigComplex b = new BigComplex(); 218 GroebnerBase<BigComplex> bba; 219 220 bba = GBFactory.<BigComplex> getImplementation(b); 221 //System.out.println("bba = " + bba); 222 assertTrue("bba field " + bba, bba instanceof GroebnerBaseSeq); 223 } 224 225 226 /** 227 * Test get AlgebraicNumber<BigRational> implementation. 228 * 229 */ 230 public void testAlgebraicNumberBigRational() { 231 BigRational b = new BigRational(); 232 GenPolynomialRing<BigRational> fac; 233 fac = new GenPolynomialRing<BigRational>(b, 1); 234 GenPolynomial<BigRational> mo = fac.random(kl, ll, el, q); 235 while (mo.isZERO() || mo.isONE() || mo.isConstant()) { 236 mo = fac.random(kl, ll, el, q); 237 } 238 239 AlgebraicNumberRing<BigRational> afac; 240 afac = new AlgebraicNumberRing<BigRational>(mo); 241 242 GroebnerBase<AlgebraicNumber<BigRational>> bba; 243 244 bba = GBFactory.<AlgebraicNumber<BigRational>> getImplementation(afac); 245 //System.out.println("bba1 = " + bba); 246 assertTrue("bba algebraic ring " + bba, bba instanceof GroebnerBasePseudoSeq); 247 248 mo = fac.univariate(0).subtract(fac.getONE()); 249 afac = new AlgebraicNumberRing<BigRational>(mo, true); 250 251 bba = GBFactory.<AlgebraicNumber<BigRational>> getImplementation(afac); 252 //System.out.println("bba1 = " + bba); 253 assertTrue("bba algebraic field " + bba, bba instanceof GroebnerBaseSeq); 254 } 255 256 257 /** 258 * Test get AlgebraicNumber<ModInteger> implementation. 259 * 260 */ 261 public void testAlgebraicNumberModInteger() { 262 ModIntegerRing b = new ModIntegerRing(19, true); 263 GenPolynomialRing<ModInteger> fac; 264 fac = new GenPolynomialRing<ModInteger>(b, 1); 265 GenPolynomial<ModInteger> mo = fac.random(kl, ll, el, q); 266 while (mo.isZERO() || mo.isONE() || mo.isConstant()) { 267 mo = fac.random(kl, ll, el, q); 268 } 269 270 AlgebraicNumberRing<ModInteger> afac; 271 afac = new AlgebraicNumberRing<ModInteger>(mo); 272 273 AlgebraicNumber<ModInteger> a = afac.getONE(); 274 GroebnerBase<AlgebraicNumber<ModInteger>> bba; 275 276 bba = GBFactory.<AlgebraicNumber<ModInteger>> getImplementation(afac); 277 //System.out.println("bba2 = " + bba); 278 assertTrue("bba algebraic ring " + bba, bba instanceof GroebnerBasePseudoSeq); 279 } 280 281 282 /** 283 * Test get GenPolynomial implementation. 284 * 285 */ 286 public void testGenPolynomial() { 287 BigRational b = new BigRational(); 288 GenPolynomialRing<BigRational> fac; 289 fac = new GenPolynomialRing<BigRational>(b, rl, to); 290 RingFactory<GenPolynomial<BigRational>> rf = fac; 291 292 GroebnerBase<GenPolynomial<BigRational>> bba; 293 294 bba = GBFactory.getImplementation(fac); 295 //System.out.println("bba = " + bba); 296 assertTrue("bba recursive polynomial " + bba, bba instanceof GroebnerBasePseudoRecSeq); 297 298 GroebnerBase<BigRational> bb; 299 bb = GBFactory.<BigRational>getImplementation((RingFactory)rf); 300 //System.out.println("bb = " + bb); 301 assertTrue("bba recursive polynomial " + bb, bb instanceof GroebnerBasePseudoRecSeq); 302 } 303 304 305 /** 306 * Test get Product implementation. 307 * 308 */ 309 public void testProduct() { 310 ModIntegerRing mi = new ModIntegerRing(19, true); 311 ProductRing<ModInteger> fac; 312 fac = new ProductRing<ModInteger>(mi, 3); 313 RingFactory<Product<ModInteger>> rf = fac; 314 315 GroebnerBase<Product<ModInteger>> bba; 316 317 bba = GBFactory.getImplementation(fac); 318 //System.out.println("bba = " + bba); 319 assertTrue("bba product " + bba, bba instanceof RGroebnerBaseSeq); 320 321 mi = new ModIntegerRing(30); 322 fac = new ProductRing<ModInteger>(mi, 3); 323 rf = fac; 324 325 GroebnerBase<Product<ModInteger>> bb; 326 bb = GBFactory.<Product<ModInteger>>getImplementation((RingFactory)rf); 327 //System.out.println("bb = " + bb); 328 assertTrue("bba product " + bb, bb instanceof RGroebnerBasePseudoSeq); 329 } 330 331 332 /** 333 * Test get proxy implementation. 334 * 335 */ 336 public void testProxy() { 337 BigRational b = new BigRational(); 338 GroebnerBaseAbstract<BigRational> bba; 339 340 bba = GBFactory.getProxy(b); 341 //System.out.println("bba = " + bba); 342 assertTrue("bba field " + bba, bba instanceof GBProxy); 343 bba.terminate(); 344 345 346 ModIntegerRing m = new ModIntegerRing(2*3); 347 GroebnerBaseAbstract<ModInteger> bbm; 348 349 bbm = GBFactory.getProxy(m); 350 //System.out.println("bba = " + bba); 351 assertTrue("bbm ! field " + bbm, ! (bbm instanceof GBProxy) ); 352 bbm.terminate(); 353 } 354 355 }