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