001/* 002 * $Id: FactorFractionTest.java 5688 2017-01-03 08:45:09Z 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 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 //BasicConfigurator.configure(); 034 junit.textui.TestRunner.run(suite()); 035 } 036 037 038 /** 039 * Constructs a <CODE>FactorFractionTest</CODE> object. 040 * @param name String. 041 */ 042 public FactorFractionTest(String name) { 043 super(name); 044 } 045 046 047 /** 048 */ 049 public static Test suite() { 050 TestSuite suite = new TestSuite(FactorFractionTest.class); 051 return suite; 052 } 053 054 055 int rl = 1; 056 057 058 int kl = 3; 059 060 061 int ll = 4; 062 063 064 int el = 4; 065 066 067 float q = 0.5f; 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 String[] vars = new String[]{ "z" }; 081 mfac = new GenPolynomialRing<BigRational>(cfac, rl, to, vars); 082 efac = new QuotientRing<BigRational>(mfac); 083 } 084 085 086 @Override 087 protected void tearDown() { 088 //efac.terminate(); 089 efac = null; 090 ComputerThreads.terminate(); 091 } 092 093 094 /** 095 * Test quotient coefficient polynomial factorization. 096 */ 097 public void testQuotientFactorization() { 098 Quotient<BigRational> a = efac.random(kl, ll, el, q); // will be irreducible most times 099 //System.out.println("a = " + a); 100 a = a.power(3); 101 Quotient<BigRational> b = efac.random(kl, ll, el, q); // will be irreducible most times 102 //System.out.println("b = " + b); 103 Quotient<BigRational> c = a.multiply(b); 104 //System.out.println("c = " + c); 105 106 FactorFraction<BigRational,Quotient<BigRational>> engine = new FactorFraction<BigRational,Quotient<BigRational>>(efac); 107 //System.out.println("engine = " + engine); 108 109 SortedMap<Quotient<BigRational>, Long> sm = engine.factors(c); 110 //System.out.println("factors(c) = " + sm); 111 if (c.isZERO()) { 112 assertTrue("#facs == 0", sm.size() == 0); 113 } else { 114 assertTrue("#facs >= 1", sm.size() >= 1); 115 } 116 117 for (Quotient<BigRational> q : sm.keySet()) { 118 assertTrue("irred(q): " + q, engine.isIrreducible(q)); 119 } 120 boolean t = engine.isFactorization(c, sm); 121 //System.out.println("t = " + t); 122 assertTrue("prod(factor(c)) == c", t); 123 } 124 125}