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