001    /*
002     * $Id: PolyUfdUtilTest.java 3295 2010-08-26 17:01:10Z kredel $
003     */
004    
005    package edu.jas.ufd;
006    
007    
008    import junit.framework.Test;
009    import junit.framework.TestCase;
010    import junit.framework.TestSuite;
011    
012    import edu.jas.arith.BigInteger;
013    import edu.jas.kern.ComputerThreads;
014    import edu.jas.poly.GenPolynomial;
015    import edu.jas.poly.GenPolynomialRing;
016    import edu.jas.poly.TermOrder;
017    
018    
019    /**
020     * PolyUfdUtil tests with JUnit.
021     * @author Heinz Kredel.
022     */
023    
024    public class PolyUfdUtilTest extends TestCase {
025    
026    
027        /**
028         * main.
029         */
030        public static void main(String[] args) {
031            //BasicConfigurator.configure();
032            junit.textui.TestRunner.run(suite());
033            ComputerThreads.terminate();
034        }
035    
036    
037        /**
038         * Constructs a <CODE>PolyUtilTest</CODE> object.
039         * @param name String.
040         */
041        public PolyUfdUtilTest(String name) {
042            super(name);
043        }
044    
045    
046        /**
047         */
048        public static Test suite() {
049            TestSuite suite = new TestSuite(PolyUfdUtilTest.class);
050            return suite;
051        }
052    
053    
054        //private final static int bitlen = 100;
055    
056        TermOrder to = new TermOrder(TermOrder.INVLEX);
057    
058    
059        GenPolynomialRing<BigInteger> dfac;
060    
061    
062        GenPolynomialRing<BigInteger> cfac;
063    
064    
065        GenPolynomialRing<GenPolynomial<BigInteger>> rfac;
066    
067    
068        BigInteger ai;
069    
070    
071        BigInteger bi;
072    
073    
074        BigInteger ci;
075    
076    
077        BigInteger di;
078    
079    
080        BigInteger ei;
081    
082    
083        GenPolynomial<BigInteger> a;
084    
085    
086        GenPolynomial<BigInteger> b;
087    
088    
089        GenPolynomial<BigInteger> c;
090    
091    
092        GenPolynomial<BigInteger> d;
093    
094    
095        GenPolynomial<BigInteger> e;
096    
097    
098        int rl = 5;
099    
100    
101        int kl = 5;
102    
103    
104        int ll = 5;
105    
106    
107        int el = 3;
108    
109    
110        float q = 0.3f;
111    
112    
113        @Override
114        protected void setUp() {
115            a = b = c = d = e = null;
116            ai = bi = ci = di = ei = null;
117            dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl, to);
118            cfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl - 1, to);
119            rfac = new GenPolynomialRing<GenPolynomial<BigInteger>>(cfac, 1, to);
120        }
121    
122    
123        @Override
124        protected void tearDown() {
125            a = b = c = d = e = null;
126            ai = bi = ci = di = ei = null;
127            dfac = null;
128            cfac = null;
129            rfac = null;
130        }
131    
132    
133        protected static java.math.BigInteger getPrime1() {
134            long prime = 2; //2^60-93; // 2^30-35; //19; knuth (2,390)
135            for (int i = 1; i < 60; i++) {
136                prime *= 2;
137            }
138            prime -= 93;
139            //prime = 37;
140            //System.out.println("p1 = " + prime);
141            return new java.math.BigInteger("" + prime);
142        }
143    
144    
145        protected static java.math.BigInteger getPrime2() {
146            long prime = 2; //2^60-93; // 2^30-35; //19; knuth (2,390)
147            for (int i = 1; i < 30; i++) {
148                prime *= 2;
149            }
150            prime -= 35;
151            //prime = 19;
152            //System.out.println("p1 = " + prime);
153            return new java.math.BigInteger("" + prime);
154        }
155    
156    
157        /**
158         * Test Kronecker substitution.
159         * 
160         */
161        public void testKroneckerSubstitution() {
162    
163            for (int i = 0; i < 10; i++) {
164                a = dfac.random(kl, ll * 2, el * 5, q);
165                long d = a.degree() + 1L;
166                //System.out.println("\na        = " + a);
167                //System.out.println("deg(a)+1 = " + d);
168    
169                b = PolyUfdUtil.<BigInteger> substituteKronecker(a, d);
170                //System.out.println("b        = " + b);
171    
172                c = PolyUfdUtil.<BigInteger> backSubstituteKronecker(dfac, b, d);
173                //System.out.println("c        = " + c);
174                e = a.subtract(c);
175                //System.out.println("e        = " + e);
176                assertTrue("back(subst(a)) = a", e.isZERO());
177            }
178        }
179    
180    }