001/* 002 * $Id$ 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 fractions (of polynomial quotients) tests with JUnit. 023 * @author Heinz Kredel 024 */ 025 026public class FactorFractionTest 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>FactorFractionTest</CODE> object. 039 * @param name String. 040 */ 041 public FactorFractionTest(String name) { 042 super(name); 043 } 044 045 046 /** 047 */ 048 public static Test suite() { 049 TestSuite suite = new TestSuite(FactorFractionTest.class); 050 return suite; 051 } 052 053 054 int rl = 1; 055 056 057 int kl = 3; 058 059 060 int ll = 4; 061 062 063 int el = 4; 064 065 066 float q = 0.5f; 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 String[] vars = new String[]{ "z" }; 080 mfac = new GenPolynomialRing<BigRational>(cfac, rl, to, vars); 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 quotient coefficient polynomial factorization. 095 */ 096 public void testQuotientFactorization() { 097 Quotient<BigRational> a = efac.random(kl, ll, el, q); // will be irreducible most times 098 //System.out.println("a = " + a); 099 a = a.power(3); 100 Quotient<BigRational> b = efac.random(kl, ll, el, q); // will be irreducible most times 101 //System.out.println("b = " + b); 102 Quotient<BigRational> c = a.multiply(b); 103 //System.out.println("c = " + c); 104 105 FactorFraction<BigRational,Quotient<BigRational>> engine = new FactorFraction<BigRational,Quotient<BigRational>>(efac); 106 //System.out.println("engine = " + engine); 107 108 SortedMap<Quotient<BigRational>, Long> sm = engine.factors(c); 109 //System.out.println("factors(c) = " + sm); 110 if (c.isZERO()) { 111 assertTrue("#facs == 0", sm.size() == 0); 112 } else { 113 assertTrue("#facs >= 1", sm.size() >= 1); 114 } 115 116 for (Quotient<BigRational> q : sm.keySet()) { 117 assertTrue("irred(q): " + q, engine.isIrreducible(q)); 118 } 119 boolean t = engine.isFactorization(c, sm); 120 //System.out.println("t = " + t); 121 assertTrue("prod(factor(c)) == c", t); 122 } 123 124}