001/*
002 * $Id: ElementaryIntegrationAbsoluteTest.java 5812 2018-04-25 21:28:02Z kredel
003 * $
004 */
005
006package edu.jas.integrate;
007
008
009import edu.jas.arith.BigRational;
010import edu.jas.kern.ComputerThreads;
011import edu.jas.poly.GenPolynomial;
012import edu.jas.poly.GenPolynomialRing;
013import edu.jas.poly.TermOrder;
014import edu.jas.ufd.Quotient;
015import edu.jas.ufd.QuotientRing;
016
017import junit.framework.Test;
018import junit.framework.TestCase;
019import junit.framework.TestSuite;
020
021
022/**
023 * Elementary integration Bernoulli algorithm with linear factors with JUnit.
024 * @author Heinz Kredel
025 */
026
027public class ElementaryIntegrationAbsoluteTest extends TestCase {
028
029
030    /**
031     * main.
032     */
033    public static void main(String[] args) {
034        //BasicConfigurator.configure(); 
035        junit.textui.TestRunner.run(suite());
036    }
037
038
039    /**
040     * Constructs a <CODE>ElementaryIntegrationAbsoluteTest</CODE> object.
041     * @param name String.
042     */
043    public ElementaryIntegrationAbsoluteTest(String name) {
044        super(name);
045    }
046
047
048    /**
049     * suite.
050     */
051    public static Test suite() {
052        TestSuite suite = new TestSuite(ElementaryIntegrationAbsoluteTest.class);
053        return suite;
054    }
055
056
057    TermOrder tord;
058
059
060    QuotientRing<BigRational> qfac;
061
062
063    GenPolynomialRing<BigRational> pfac;
064
065
066    ElementaryIntegration<BigRational> integrator;
067
068
069    QuotIntegral<BigRational> rint;
070
071
072    @Override
073    protected void setUp() {
074        tord = new TermOrder(TermOrder.INVLEX);
075        BigRational br = new BigRational(1);
076        String[] vars = new String[] { "x" };
077        pfac = new GenPolynomialRing<BigRational>(br, 1, tord, vars);
078        qfac = new QuotientRing<BigRational>(pfac);
079        integrator = new ElementaryIntegrationBernoulli<BigRational>(br);
080    }
081
082
083    @Override
084    protected void tearDown() {
085        ComputerThreads.terminate();
086    }
087
088
089    /**
090     * Test Bernoulli algorithm.
091     */
092    public void testRationalBernoulli() {
093        GenPolynomial<BigRational> agen = pfac.univariate(0, 4);
094        agen = agen.sum(pfac.fromInteger(4)); // x^4 + 4
095
096        // GenPolynomial<BigRational> x6 = pfac.univariate(0, 6);
097        // GenPolynomial<BigRational> x4 = pfac.univariate(0, 4);
098        // GenPolynomial<BigRational> x2 = pfac.univariate(0, 2);
099        // // x^6 - 5 x^4 + 5 x^2 + 4
100        // agen = x6.subtract(x4.multiply(pfac.fromInteger(5))); 
101        // agen = agen.sum(x2.multiply(pfac.fromInteger(5))); 
102        // agen = agen.sum(pfac.fromInteger(4)); 
103
104        // GenPolynomial<BigRational> x3 = pfac.univariate(0, 3);
105        // GenPolynomial<BigRational> x = pfac.univariate(0);
106        // // x^3 + x
107        // agen = x3.sum(x); 
108
109        // GenPolynomial<BigRational> x2 = pfac.univariate(0, 2);
110        // // x^2 - 2
111        // agen = x2.subtract(pfac.fromInteger(2));
112
113        GenPolynomial<BigRational> N = pfac.getONE();
114        Quotient<BigRational> Q = new Quotient<BigRational>(qfac, N, agen);
115
116        rint = integrator.integrate(Q);
117        //System.out.println("\nquot integral: " + rint.toString());
118        assertTrue("isIntegral ", integrator.isIntegral(rint));
119    }
120
121}