001/* 002 * $Id: FactorQuotientTest.java 4010 2012-07-21 20:39:56Z kredel $ 003 */ 004 005package edu.jas.ufd; 006 007 008import java.util.SortedMap; 009 010import junit.framework.Test; 011import junit.framework.TestCase; 012import junit.framework.TestSuite; 013 014import edu.jas.arith.BigRational; 015import edu.jas.kern.ComputerThreads; 016import edu.jas.poly.GenPolynomial; 017import edu.jas.poly.GenPolynomialRing; 018import edu.jas.poly.TermOrder; 019 020 021/** 022 * Factor quotient tests with JUnit. 023 * @author Heinz Kredel. 024 */ 025 026public class FactorQuotientTest extends TestCase { 027 028 029 /** 030 * main. 031 */ 032 public static void main(String[] args) { 033 //BasicConfigurator.configure(); 034 junit.textui.TestRunner.run(suite()); 035 } 036 037 038 /** 039 * Constructs a <CODE>FactorQuotientTest</CODE> object. 040 * @param name String. 041 */ 042 public FactorQuotientTest(String name) { 043 super(name); 044 } 045 046 047 /** 048 */ 049 public static Test suite() { 050 TestSuite suite = new TestSuite(FactorQuotientTest.class); 051 return suite; 052 } 053 054 055 int rl = 1; 056 057 058 int kl = 3; 059 060 061 int ll = 3; 062 063 064 int el = 3; 065 066 067 float q = 0.4f; 068 069 070 QuotientRing<BigRational> efac; 071 072 073 GenPolynomialRing<BigRational> mfac; 074 075 076 @Override 077 protected void setUp() { 078 BigRational cfac = new BigRational(1); 079 TermOrder to = new TermOrder(TermOrder.INVLEX); 080 mfac = new GenPolynomialRing<BigRational>(cfac, rl, to); 081 efac = new QuotientRing<BigRational>(mfac); 082 } 083 084 085 @Override 086 protected void tearDown() { 087 //efac.terminate(); 088 efac = null; 089 ComputerThreads.terminate(); 090 } 091 092 093 /** 094 * Test dummy for Junit. 095 * 096 */ 097 public void xtestDummy() { 098 } 099 100 101 /** 102 * Test quotient coefficient polynomial factorization. 103 * 104 */ 105 public void testQuotientFactorization() { 106 107 TermOrder to = new TermOrder(TermOrder.INVLEX); 108 //BigRational cfac = new BigRational(1); 109 110 String[] var_x = new String[] { "x" }; 111 GenPolynomialRing<Quotient<BigRational>> pfac = new GenPolynomialRing<Quotient<BigRational>>(efac, 1, 112 to, var_x); 113 //System.out.println("pfac = " + pfac.toScript()); 114 115 GenPolynomial<Quotient<BigRational>> a = pfac.random(kl, ll, el, q); // will be irreducible most times 116 //System.out.println("a = " + a); 117 118 FactorAbstract<Quotient<BigRational>> engine = FactorFactory.getImplementation(efac); 119 //System.out.println("engine = " + engine); 120 121 SortedMap<GenPolynomial<Quotient<BigRational>>, Long> sm = engine.factors(a); 122 //System.out.println("factors(a) = " + sm); 123 124 assertTrue("#facs >= 1", sm.size() >= 1); 125 126 boolean t = engine.isFactorization(a, sm); 127 //System.out.println("t = " + t); 128 assertTrue("prod(factor(a)) = a", t); 129 } 130 131}