001/*
002 * $Id: TermOrderByNameCompatTest.java 5396 2016-01-05 12:34:24Z axelclk $
003 */
004
005package edu.jas.poly;
006
007
008import junit.framework.Test;
009import junit.framework.TestCase;
010import junit.framework.TestSuite;
011
012import org.apache.log4j.BasicConfigurator;
013
014import edu.jas.arith.BigInteger;
015
016
017/**
018 * TermOrderByName compatibility tests with JUnit. Tests different TermOrders.
019 * @author Axel Kramer
020 */
021
022public class TermOrderByNameCompatTest extends TestCase {
023
024
025    /**
026     * main.
027     */
028    public static void main(String[] args) {
029        BasicConfigurator.configure();
030        junit.textui.TestRunner.run(suite());
031    }
032
033
034    /**
035     * Constructs a <CODE>TermOrderByNameCompatTest</CODE> object.
036     * @param name String.
037     */
038    public TermOrderByNameCompatTest(String name) {
039        super(name);
040    }
041
042
043    /**
044     * suite.
045     */
046    public static Test suite() {
047        TestSuite suite = new TestSuite(TermOrderByNameCompatTest.class);
048        return suite;
049    }
050
051
052    @Override
053    protected void setUp() {
054    }
055
056
057    @Override
058    protected void tearDown() {
059    }
060
061
062    /**
063     * Test order Lexicographic.
064     */
065    public void testTermOrderLexicographic() {
066        // integers
067        BigInteger rf = new BigInteger();
068        String[] v = new String[] { "x", "y", "z" };
069
070        String testPolynomial = "-10*x^5*y^4*z^2 + 7*x^2*y^5*z^3 - 10*x^2*y*z^5 - 7*x*y^5*z^4 + 6*x*y^4*z^3 + 6*x*y^3*z^3 + 3*x*y^2*z + y^4*z - 7*y^2*z + 2*z^5";
071
072        // polynomials over integral numbers
073        GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf,
074                        TermOrderByName.Lexicographic, v);
075        // test order Lexicographic of polynomial:
076        GenPolynomial<BigInteger> p = pf.parse(testPolynomial);
077
078        // -10*x^5*y^4*z^2,7*x^2*y^5*z^3,-10*x^2*y*z^5,-7*x*y^5*z^4,6*x*y^4*z^3,6*x*y^3*z^3,3*x*y^2*z,y^4*z,-7*y^2*z,2*z^5 
079        assertEquals("( -10 ) x^5 * y^4 * z^2 + 7 x^2 * y^5 * z^3 - 10 x^2 * y * z^5 - 7 x * y^5 * z^4 + 6 x * y^4 * z^3 + 6 x * y^3 * z^3 + 3 x * y^2 * z + y^4 * z - 7 y^2 * z + 2 z^5",
080                        p.toString());
081    }
082
083
084    /**
085     * Test order NegativeLexicographic.
086     */
087    public void testTermOrderNegativeLexicographic() {
088        // integers
089        BigInteger rf = new BigInteger();
090        String[] v = new String[] { "x", "y", "z" };
091
092        String testPolynomial = "-10*x^5*y^4*z^2 + 7*x^2*y^5*z^3 - 10*x^2*y*z^5 - 7*x*y^5*z^4 + 6*x*y^4*z^3 + 6*x*y^3*z^3 + 3*x*y^2*z + y^4*z - 7*y^2*z + 2*z^5";
093
094        // polynomials over integral numbers
095        GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf,
096                        TermOrderByName.NegativeLexicographic, v);
097        // test order NegativeLexicographic of polynomial:
098        GenPolynomial<BigInteger> p = pf.parse(testPolynomial);
099
100        // 2*z^5,-7*y^2*z,y^4*z,3*x*y^2*z,6*x*y^3*z^3,6*x*y^4*z^3,-7*x*y^5*z^4,-10*x^2*y*z^5,7*x^2*y^5*z^3,-10*x^5*y^4*z^2
101        assertEquals("2 z^5 - 7 y^2 * z + y^4 * z + 3 x * y^2 * z + 6 x * y^3 * z^3 + 6 x * y^4 * z^3 - 7 x * y^5 * z^4 - 10 x^2 * y * z^5 + 7 x^2 * y^5 * z^3 - 10 x^5 * y^4 * z^2",
102                        p.toString());
103
104    }
105
106
107    /**
108     * Test order DegreeLexicographic.
109     */
110    public void testTermOrderDegreeLexicographic() {
111        // integers
112        BigInteger rf = new BigInteger();
113        String[] v = new String[] { "x", "y", "z" };
114
115        String testPolynomial = "-10*x^5*y^4*z^2 + 7*x^2*y^5*z^3 - 10*x^2*y*z^5 - 7*x*y^5*z^4 + 6*x*y^4*z^3 + 6*x*y^3*z^3 + 3*x*y^2*z + y^4*z - 7*y^2*z + 2*z^5";
116        // polynomials over integral numbers
117        GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf,
118                        TermOrderByName.DegreeLexicographic, v);
119        // test order DegreeLexicographic of polynomial:
120        GenPolynomial<BigInteger> p = pf.parse(testPolynomial);
121
122        // -10*x^5*y^4*z^2,7*x^2*y^5*z^3,-7*x*y^5*z^4,-10*x^2*y*z^5,6*x*y^4*z^3,6*x*y^3*z^3,y^4*z,2*z^5,3*x*y^2*z,-7*y^2*z
123        assertEquals("( -10 ) x^5 * y^4 * z^2 + 7 x^2 * y^5 * z^3 - 7 x * y^5 * z^4 - 10 x^2 * y * z^5 + 6 x * y^4 * z^3 + 6 x * y^3 * z^3 + y^4 * z + 2 z^5 + 3 x * y^2 * z - 7 y^2 * z",
124                        p.toString());
125
126    }
127
128
129    public void testTermOrderNegativeDegreeReverseLexicographic() {
130        // integers
131        BigInteger rf = new BigInteger();
132        String[] v = new String[] { "x", "y", "z" };
133
134        String testPolynomial = "-10*x^5*y^4*z^2 + 7*x^2*y^5*z^3 - 10*x^2*y*z^5 - 7*x*y^5*z^4 + 6*x*y^4*z^3 + 6*x*y^3*z^3 + 3*x*y^2*z + y^4*z - 7*y^2*z + 2*z^5";
135
136        // polynomials over integral numbers
137        GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf,
138                        TermOrderByName.NegativeDegreeReverseLexicographic, v);
139        // test order NegativeDegreeReverseLexicographic of polynomial:
140        GenPolynomial<BigInteger> p = pf.parse(testPolynomial);
141
142        // -7*y^2*z,3*x*y^2*z,y^4*z,2*z^5,6*x*y^3*z^3,6*x*y^4*z^3,-10*x^2*y*z^5,7*x^2*y^5*z^3,-7*x*y^5*z^4,-10*x^5*y^4*z^2
143        assertEquals("( -7 ) y^2 * z + 3 x * y^2 * z + y^4 * z + 2 z^5 + 6 x * y^3 * z^3 + 6 x * y^4 * z^3 - 10 x^2 * y * z^5 + 7 x^2 * y^5 * z^3 - 7 x * y^5 * z^4 - 10 x^5 * y^4 * z^2",
144                        p.toString());
145    }
146
147
148    /**
149     * Test order DegreeReverseLexicographic.
150     */
151    public void testTermOrderDegreeReverseLexicographic() {
152        // integers
153        BigInteger rf = new BigInteger();
154        String[] v = new String[] { "x", "y", "z" };
155
156        String testPolynomial = "-10*x^5*y^4*z^2 + 7*x^2*y^5*z^3 - 10*x^2*y*z^5 - 7*x*y^5*z^4 + 6*x*y^4*z^3 + 6*x*y^3*z^3 + 3*x*y^2*z + y^4*z - 7*y^2*z + 2*z^5";
157
158        // polynomials over integral numbers
159        GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf,
160                        TermOrderByName.DegreeReverseLexicographic, v);
161        //System.out.println("pf = " + pf);
162        // test order DegreeReverseLexicographic of polynomial:
163        GenPolynomial<BigInteger> p = pf.parse(testPolynomial);
164
165        // -10*x^5*y^4*z^2,7*x^2*y^5*z^3,-7*x*y^5*z^4,6*x*y^4*z^3,-10*x^2*y*z^5,6*x*y^3*z^3,y^4*z,2*z^5,3*x*y^2*z,-7*y^2*z
166        //degrees       11,           10,          10,          8,            8,          7,    5,    5,        4,       3
167        assertEquals("( -10 ) x^5 * y^4 * z^2 + 7 x^2 * y^5 * z^3 - 7 x * y^5 * z^4 + 6 x * y^4 * z^3 - 10 x^2 * y * z^5 + 6 x * y^3 * z^3 + y^4 * z + 2 z^5 + 3 x * y^2 * z - 7 y^2 * z",
168                        p.toString());
169    }
170
171
172    /**
173     * Test order NegativeDegreeLexicographic.
174     */
175    public void testTermOrderNegativeDegreeLexicographic() {
176        // integers
177        BigInteger rf = new BigInteger();
178        String[] v = new String[] { "x", "y", "z" };
179
180        String testPolynomial = "-10*x^5*y^4*z^2 + 7*x^2*y^5*z^3 - 10*x^2*y*z^5 - 7*x*y^5*z^4 + 6*x*y^4*z^3 + 6*x*y^3*z^3 + 3*x*y^2*z + y^4*z - 7*y^2*z + 2*z^5";
181
182        // polynomials over integral numbers
183        GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf,
184                        TermOrderByName.NegativeDegreeLexicographic, v);
185        //System.out.println("pf = " + pf);
186        // test order NegativeDegreeLexicographic of polynomial:
187        GenPolynomial<BigInteger> p = pf.parse(testPolynomial);
188
189        // -7*y^2*z,3*x*y^2*z,y^4*z,2*z^5,6*x*y^3*z^3,-10*x^2*y*z^5,6*x*y^4*z^3,7*x^2*y^5*z^3,-7*x*y^5*z^4,-10*x^5*y^4*z^2
190        //degrees 3,        4,    5,    5,          7,            8,          8,           10           10,             11  
191        assertEquals("( -7 ) y^2 * z + 3 x * y^2 * z + y^4 * z + 2 z^5 + 6 x * y^3 * z^3 - 10 x^2 * y * z^5 + 6 x * y^4 * z^3 + 7 x^2 * y^5 * z^3 - 7 x * y^5 * z^4 - 10 x^5 * y^4 * z^2",
192                        p.toString());
193    }
194
195}