001/*
002 * $Id: SGBProxyTest.java 5104 2015-02-07 13:12:43Z kredel $
003 */
004
005package edu.jas.gb;
006
007
008import java.util.ArrayList;
009import java.util.List;
010
011import junit.framework.Test;
012import junit.framework.TestCase;
013import junit.framework.TestSuite;
014
015import org.apache.log4j.BasicConfigurator;
016// import org.apache.log4j.Logger;
017
018import edu.jas.arith.BigRational;
019import edu.jas.kern.ComputerThreads;
020import edu.jas.poly.GenSolvablePolynomial;
021import edu.jas.poly.GenSolvablePolynomialRing;
022import edu.jas.poly.PolynomialList;
023import edu.jas.poly.RelationGenerator;
024import edu.jas.poly.RelationTable;
025import edu.jas.poly.TermOrder;
026import edu.jas.poly.WeylRelations;
027
028
029/**
030 * SolvableGroebnerBase proxy of sequential and parallel tests with JUnit.
031 * @author Heinz Kredel.
032 */
033
034public class SGBProxyTest extends TestCase {
035
036
037    //private static final Logger logger = Logger.getLogger(SGBProxyTest.class);
038
039    /**
040     * main.
041     */
042    public static void main(String[] args) {
043        BasicConfigurator.configure();
044        junit.textui.TestRunner.run(suite());
045        ComputerThreads.terminate();
046    }
047
048
049    /**
050     * Constructs a <CODE>SGBProxyTest</CODE> object.
051     * @param name String.
052     */
053    public SGBProxyTest(String name) {
054        super(name);
055    }
056
057
058    /**
059     * suite.
060     */
061    public static Test suite() {
062        TestSuite suite = new TestSuite(SGBProxyTest.class);
063        return suite;
064    }
065
066
067    GenSolvablePolynomial<BigRational> a, b, c, d, e;
068
069
070    List<GenSolvablePolynomial<BigRational>> L;
071
072
073    PolynomialList<BigRational> F, G;
074
075
076    GenSolvablePolynomialRing<BigRational> ring;
077
078
079    SolvableGroebnerBaseAbstract<BigRational> sbb;
080
081
082    BigRational cfac;
083
084
085    TermOrder tord;
086
087
088    RelationTable<BigRational> table;
089
090
091    int rl = 4; //4; //3; 
092
093
094    int kl = 10;
095
096
097    int ll = 4;
098
099
100    int el = 2;
101
102
103    float q = 0.3f; //0.4f
104
105
106    @Override
107    protected void setUp() {
108        cfac = new BigRational(9);
109        tord = new TermOrder();
110        ring = new GenSolvablePolynomialRing<BigRational>(cfac, rl, tord);
111        table = ring.table;
112        a = b = c = d = e = null;
113        int nt = ComputerThreads.N_CPUS - 1;
114        SolvableGroebnerBaseAbstract<BigRational> bb1, bb2;
115        bb1 = new SolvableGroebnerBaseSeq<BigRational>();
116        bb2 = new SolvableGroebnerBaseParallel<BigRational>(nt);
117        sbb = new SGBProxy<BigRational>(bb1, bb2);
118
119        a = ring.random(kl, ll, el, q);
120        b = ring.random(kl, ll, el, q);
121        c = ring.random(kl, ll, el, q);
122        d = ring.random(kl, ll, el, q);
123        e = d; //ring.random(kl, ll, el, q );
124    }
125
126
127    @Override
128    protected void tearDown() {
129        a = b = c = d = e = null;
130        ring = null;
131        tord = null;
132        table = null;
133        cfac = null;
134        sbb.terminate();
135        sbb = null;
136    }
137
138
139    /**
140     * Test proxy GBase.
141     */
142    public void testProxyGBase() {
143        L = new ArrayList<GenSolvablePolynomial<BigRational>>();
144
145        L.add(a);
146        L = sbb.leftGB(L);
147        assertTrue("isLeftGB( { a } )", sbb.isLeftGB(L));
148
149        L.add(b);
150        //System.out.println("L = " + L.size() );
151        L = sbb.leftGB(L);
152        assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(L));
153
154        L.add(c);
155        L = sbb.leftGB(L);
156        assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(L));
157
158        L.add(d);
159        L = sbb.leftGB(L);
160        assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(L));
161
162        L.add(e);
163        L = sbb.leftGB(L);
164        assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(L));
165    }
166
167
168    /**
169     * Test Weyl proxy GBase.
170     */
171    public void testWeylProxyGBase() {
172        int rloc = 4;
173        ring = new GenSolvablePolynomialRing<BigRational>(cfac, rloc);
174
175        RelationGenerator<BigRational> wl = new WeylRelations<BigRational>();
176        wl.generate(ring);
177        table = ring.table;
178
179        a = ring.random(kl, ll, el, q);
180        b = ring.random(kl, ll, el, q);
181        c = ring.random(kl, ll, el, q);
182        d = ring.random(kl, ll, el, q);
183        e = d; //ring.random(kl, ll, el, q );
184
185        L = new ArrayList<GenSolvablePolynomial<BigRational>>();
186
187        L.add(a);
188        L = sbb.leftGB(L);
189        assertTrue("isLeftGB( { a } )", sbb.isLeftGB(L));
190
191        L.add(b);
192        //System.out.println("L = " + L.size() );
193        L = sbb.leftGB(L);
194        assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(L));
195
196        L.add(c);
197        L = sbb.leftGB(L);
198        assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(L));
199
200        L.add(d);
201        L = sbb.leftGB(L);
202        assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(L));
203
204        L.add(e);
205        L = sbb.leftGB(L);
206        assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(L));
207    }
208
209
210    /**
211     * Test proxy twosided GBase.
212     */
213    public void testProxyTSGBase() {
214        L = new ArrayList<GenSolvablePolynomial<BigRational>>();
215
216        L.add(a);
217        L = sbb.twosidedGB(L);
218        //System.out.println("L = " + L.size() );
219        assertTrue("isTwosidedGB( { a } )", sbb.isTwosidedGB(L));
220
221        L.add(b);
222        L = sbb.twosidedGB(L);
223        //System.out.println("L = " + L.size() );
224        assertTrue("isTwosidedGB( { a, b } )", sbb.isTwosidedGB(L));
225
226        L.add(c);
227        L = sbb.twosidedGB(L);
228        //System.out.println("L = " + L.size() );
229        assertTrue("isTwosidedGB( { a, b, c } )", sbb.isTwosidedGB(L));
230
231        L.add(d);
232        L = sbb.twosidedGB(L);
233        //System.out.println("L = " + L.size() );
234        assertTrue("isTwosidedGB( { a, b, c, d } )", sbb.isTwosidedGB(L));
235
236        L.add(e);
237        L = sbb.twosidedGB(L);
238        //System.out.println("L = " + L.size() );
239        assertTrue("isTwosidedGB( { a, b, c, d, e } )", sbb.isTwosidedGB(L));
240    }
241
242
243    /**
244     * Test Weyl proxy twosided GBase is always 1.
245     */
246    public void testWeylProxyTSGBase() {
247        int rloc = 4;
248        ring = new GenSolvablePolynomialRing<BigRational>(cfac, rloc);
249
250        RelationGenerator<BigRational> wl = new WeylRelations<BigRational>();
251        wl.generate(ring);
252        table = ring.table;
253
254        a = ring.random(kl, ll, el, q);
255        b = ring.random(kl, ll, el, q);
256        c = ring.random(kl, ll, el, q);
257        d = ring.random(kl, ll, el, q);
258        e = d; //ring.random(kl, ll, el, q );
259
260        L = new ArrayList<GenSolvablePolynomial<BigRational>>();
261
262        L.add(a);
263        //System.out.println("La = " + L );
264        L = sbb.twosidedGB(L);
265        //System.out.println("L = " + L );
266        assertTrue("isTwosidedGB( { a } )", sbb.isTwosidedGB(L));
267
268        L.add(b);
269        L = sbb.twosidedGB(L);
270        //System.out.println("L = " + L );
271        assertTrue("isTwosidedGB( { a, b } )", sbb.isTwosidedGB(L));
272
273        L.add(c);
274        L = sbb.twosidedGB(L);
275        //System.out.println("L = " + L );
276        assertTrue("isTwosidedGB( { a, b, c } )", sbb.isTwosidedGB(L));
277
278        L.add(d);
279        L = sbb.twosidedGB(L);
280        //System.out.println("L = " + L );
281        assertTrue("isTwosidedGB( { a, b, c, d } )", sbb.isTwosidedGB(L));
282
283        L.add(e);
284        L = sbb.twosidedGB(L);
285        //System.out.println("L = " + L );
286        assertTrue("isTwosidedGB( { a, b, c, d, e } )", sbb.isTwosidedGB(L));
287    }
288
289}