001/* 002 * $Id: FactorQuotientTest.java 5863 2018-07-20 11:13:34Z 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 junit.textui.TestRunner.run(suite()); 034 } 035 036 037 /** 038 * Constructs a <CODE>FactorQuotientTest</CODE> object. 039 * @param name String. 040 */ 041 public FactorQuotientTest(String name) { 042 super(name); 043 } 044 045 046 /** 047 */ 048 public static Test suite() { 049 TestSuite suite = new TestSuite(FactorQuotientTest.class); 050 return suite; 051 } 052 053 054 int rl = 1; 055 056 057 int kl = 3; 058 059 060 int ll = 3; 061 062 063 int el = 3; 064 065 066 float q = 0.4f; 067 068 069 QuotientRing<BigRational> efac; 070 071 072 GenPolynomialRing<BigRational> mfac; 073 074 075 @Override 076 protected void setUp() { 077 BigRational cfac = new BigRational(1); 078 TermOrder to = new TermOrder(TermOrder.INVLEX); 079 mfac = new GenPolynomialRing<BigRational>(cfac, rl, to); 080 efac = new QuotientRing<BigRational>(mfac); 081 } 082 083 084 @Override 085 protected void tearDown() { 086 //efac.terminate(); 087 efac = null; 088 ComputerThreads.terminate(); 089 } 090 091 092 /** 093 * Test dummy for Junit. 094 * 095 */ 096 public void xtestDummy() { 097 } 098 099 100 /** 101 * Test quotient coefficient polynomial factorization. 102 * 103 */ 104 public void testQuotientFactorization() { 105 106 TermOrder to = new TermOrder(TermOrder.INVLEX); 107 //BigRational cfac = new BigRational(1); 108 109 String[] var_x = new String[] { "x" }; 110 GenPolynomialRing<Quotient<BigRational>> pfac = new GenPolynomialRing<Quotient<BigRational>>(efac, 1, 111 to, var_x); 112 //System.out.println("pfac = " + pfac.toScript()); 113 114 GenPolynomial<Quotient<BigRational>> a = pfac.random(kl, ll, el, q); // will be irreducible most times 115 //System.out.println("a = " + a); 116 a = a.multiply(a.sum(pfac.getONE())); 117 //System.out.println("a = " + a); 118 119 FactorAbstract<Quotient<BigRational>> engine = FactorFactory.getImplementation(efac); 120 //System.out.println("engine = " + engine); 121 122 SortedMap<GenPolynomial<Quotient<BigRational>>, Long> sm = engine.factors(a); 123 //System.out.println("factors(a) = " + sm); 124 125 assertTrue("#facs >= 1", sm.size() >= 1); 126 127 boolean t = engine.isFactorization(a, sm); 128 //System.out.println("t = " + t); 129 assertTrue("prod(factor(a)) = a", t); 130 } 131 132}