001/* 002 * $Id: GBFactoryTest.java 4015 2012-07-22 12:05:38Z kredel $ 003 */ 004 005package edu.jas.gbufd; 006 007 008//import java.util.Map; 009 010import junit.framework.Test; 011import junit.framework.TestCase; 012import junit.framework.TestSuite; 013 014import org.apache.log4j.BasicConfigurator; 015 016import edu.jas.arith.BigComplex; 017import edu.jas.arith.BigInteger; 018import edu.jas.arith.BigRational; 019import edu.jas.arith.ModInteger; 020import edu.jas.arith.ModIntegerRing; 021import edu.jas.arith.Product; 022import edu.jas.arith.ProductRing; 023import edu.jas.gb.GBProxy; 024import edu.jas.gb.GroebnerBase; 025import edu.jas.gb.GroebnerBaseAbstract; 026import edu.jas.gb.GroebnerBaseSeq; 027import edu.jas.poly.AlgebraicNumber; 028import edu.jas.poly.AlgebraicNumberRing; 029import edu.jas.poly.GenPolynomial; 030import edu.jas.poly.GenPolynomialRing; 031import edu.jas.poly.TermOrder; 032import edu.jas.structure.RingFactory; 033 034 035/** 036 * GreatestCommonDivisor 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 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 assertTrue("a == 1 " + a, a.isONE()); 275 GroebnerBase<AlgebraicNumber<ModInteger>> bba; 276 277 bba = GBFactory.<AlgebraicNumber<ModInteger>> getImplementation(afac); 278 //System.out.println("bba2 = " + bba); 279 assertTrue("bba algebraic ring " + bba, bba instanceof GroebnerBasePseudoSeq); 280 } 281 282 283 /** 284 * Test get GenPolynomial implementation. 285 * 286 */ 287 public void testGenPolynomial() { 288 BigRational b = new BigRational(); 289 GenPolynomialRing<BigRational> fac; 290 fac = new GenPolynomialRing<BigRational>(b, rl, to); 291 RingFactory<GenPolynomial<BigRational>> rf = fac; 292 293 GroebnerBase<GenPolynomial<BigRational>> bba; 294 295 bba = GBFactory.getImplementation(fac); 296 //System.out.println("bba = " + bba); 297 assertTrue("bba recursive polynomial " + bba, bba instanceof GroebnerBasePseudoRecSeq); 298 299 GroebnerBase<BigRational> bb; 300 bb = GBFactory.<BigRational>getImplementation((RingFactory)rf); 301 //System.out.println("bb = " + bb); 302 assertTrue("bba recursive polynomial " + bb, bb instanceof GroebnerBasePseudoRecSeq); 303 } 304 305 306 /** 307 * Test get Product implementation. 308 * 309 */ 310 public void testProduct() { 311 ModIntegerRing mi = new ModIntegerRing(19, true); 312 ProductRing<ModInteger> fac; 313 fac = new ProductRing<ModInteger>(mi, 3); 314 RingFactory<Product<ModInteger>> rf = fac; 315 316 GroebnerBase<Product<ModInteger>> bba; 317 318 bba = GBFactory.getImplementation(fac); 319 //System.out.println("bba = " + bba); 320 assertTrue("bba product " + bba, bba instanceof RGroebnerBaseSeq); 321 322 mi = new ModIntegerRing(30); 323 fac = new ProductRing<ModInteger>(mi, 3); 324 rf = fac; 325 326 GroebnerBase<Product<ModInteger>> bb; 327 bb = GBFactory.<Product<ModInteger>>getImplementation((RingFactory)rf); 328 //System.out.println("bb = " + bb); 329 assertTrue("bba product " + bb, bb instanceof RGroebnerBasePseudoSeq); 330 } 331 332 333 /** 334 * Test get proxy implementation. 335 * 336 */ 337 public void testProxy() { 338 BigRational b = new BigRational(); 339 GroebnerBaseAbstract<BigRational> bba; 340 341 bba = GBFactory.getProxy(b); 342 //System.out.println("bba = " + bba); 343 assertTrue("bba field " + bba, bba instanceof GBProxy); 344 bba.terminate(); 345 346 347 ModIntegerRing m = new ModIntegerRing(2*3); 348 GroebnerBaseAbstract<ModInteger> bbm; 349 350 bbm = GBFactory.getProxy(m); 351 //System.out.println("bba = " + bba); 352 assertTrue("bbm ! field " + bbm, ! (bbm instanceof GBProxy) ); 353 bbm.terminate(); 354 } 355 356}