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 junit.textui.TestRunner.run(suite()); 035 } 036 037 038 /** 039 * Constructs a <CODE>ElementaryIntegrationAbsoluteTest</CODE> object. 040 * @param name String. 041 */ 042 public ElementaryIntegrationAbsoluteTest(String name) { 043 super(name); 044 } 045 046 047 /** 048 * suite. 049 */ 050 public static Test suite() { 051 TestSuite suite = new TestSuite(ElementaryIntegrationAbsoluteTest.class); 052 return suite; 053 } 054 055 056 TermOrder tord; 057 058 059 QuotientRing<BigRational> qfac; 060 061 062 GenPolynomialRing<BigRational> pfac; 063 064 065 ElementaryIntegration<BigRational> integrator; 066 067 068 QuotIntegral<BigRational> rint; 069 070 071 @Override 072 protected void setUp() { 073 tord = new TermOrder(TermOrder.INVLEX); 074 BigRational br = new BigRational(1); 075 String[] vars = new String[] { "x" }; 076 pfac = new GenPolynomialRing<BigRational>(br, 1, tord, vars); 077 qfac = new QuotientRing<BigRational>(pfac); 078 integrator = new ElementaryIntegrationBernoulli<BigRational>(br); 079 } 080 081 082 @Override 083 protected void tearDown() { 084 ComputerThreads.terminate(); 085 } 086 087 088 /** 089 * Test Bernoulli algorithm. 090 */ 091 public void testRationalBernoulli() { 092 GenPolynomial<BigRational> agen = pfac.univariate(0, 4); 093 agen = agen.sum(pfac.fromInteger(4)); // x^4 + 4 094 095 // GenPolynomial<BigRational> x6 = pfac.univariate(0, 6); 096 // GenPolynomial<BigRational> x4 = pfac.univariate(0, 4); 097 // GenPolynomial<BigRational> x2 = pfac.univariate(0, 2); 098 // // x^6 - 5 x^4 + 5 x^2 + 4 099 // agen = x6.subtract(x4.multiply(pfac.fromInteger(5))); 100 // agen = agen.sum(x2.multiply(pfac.fromInteger(5))); 101 // agen = agen.sum(pfac.fromInteger(4)); 102 103 // GenPolynomial<BigRational> x3 = pfac.univariate(0, 3); 104 // GenPolynomial<BigRational> x = pfac.univariate(0); 105 // // x^3 + x 106 // agen = x3.sum(x); 107 108 // GenPolynomial<BigRational> x2 = pfac.univariate(0, 2); 109 // // x^2 - 2 110 // agen = x2.subtract(pfac.fromInteger(2)); 111 112 GenPolynomial<BigRational> N = pfac.getONE(); 113 Quotient<BigRational> Q = new Quotient<BigRational>(qfac, N, agen); 114 115 rint = integrator.integrate(Q); 116 //System.out.println("\nquot integral: " + rint.toString()); 117 assertTrue("isIntegral ", integrator.isIntegral(rint)); 118 } 119 120}