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