/** Test accessors. */
  public void testAccessors() {
    // rational numbers
    BigRational rf = new BigRational();
    // System.out.println("rf = " + rf);

    // polynomials over rational numbers
    GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(rf, rl);
    // System.out.println("pf = " + pf);

    // test 1
    GenPolynomial<BigRational> p = pf.getONE();
    // System.out.println("p = " + p);

    ExpVector e = p.leadingExpVector();
    BigRational c = p.leadingBaseCoefficient();

    GenPolynomial<BigRational> f = new GenPolynomial<BigRational>(pf, c, e);
    assertEquals("1 == 1 ", p, f);

    GenPolynomial<BigRational> r = p.reductum();
    assertTrue("red(1) == 0 ", r.isZERO());

    // test 0
    p = pf.getZERO();
    // System.out.println("p = " + p);
    e = p.leadingExpVector();
    c = p.leadingBaseCoefficient();

    f = new GenPolynomial<BigRational>(pf, c, e);
    assertEquals("0 == 0 ", p, f);

    r = p.reductum();
    assertTrue("red(0) == 0 ", r.isZERO());

    // test random
    p = pf.random(kl, 2 * ll, el, q);
    // System.out.println("p = " + p);
    e = p.leadingExpVector();
    c = p.leadingBaseCoefficient();
    r = p.reductum();

    f = new GenPolynomial<BigRational>(pf, c, e);
    f = r.sum(f);
    assertEquals("p == lm(f)+red(f) ", p, f);

    // test iteration over random
    GenPolynomial<BigRational> g;
    g = p;
    f = pf.getZERO();
    while (!g.isZERO()) {
      e = g.leadingExpVector();
      c = g.leadingBaseCoefficient();
      // System.out.println("c e = " + c + " " + e);
      r = g.reductum();
      f = f.sum(c, e);
      g = r;
    }
    assertEquals("p == lm(f)+lm(red(f))+... ", p, f);
  }
  /** Test constructor and toString. */
  public void testConstruction() {
    c = fac.getONE();
    assertTrue("length( c ) = 1", c.length() == 1);
    assertTrue("isZERO( c )", !c.isZERO());
    assertTrue("isONE( c )", c.isONE());

    d = fac.getZERO();
    assertTrue("length( d ) = 0", d.length() == 0);
    assertTrue("isZERO( d )", d.isZERO());
    assertTrue("isONE( d )", !d.isONE());
  }
  /** Test object multiplication. */
  public void testMultiplication() {

    a = fac.random(ll);
    assertTrue("not isZERO( a )", !a.isZERO());

    b = fac.random(ll);
    assertTrue("not isZERO( b )", !b.isZERO());

    c = b.multiply(a);
    d = a.multiply(b);
    assertTrue("not isZERO( c )", !c.isZERO());
    assertTrue("not isZERO( d )", !d.isZERO());

    // System.out.println("a = " + a);
    // System.out.println("b = " + b);
    e = d.subtract(c);
    assertTrue("!isZERO( a*b-b*a ) " + e, !e.isZERO());

    assertTrue("a*b = b*a", !c.equals(d));
    // assertEquals("a*b = b*a",c,d);

    c = fac.random(ll);
    // System.out.println("c = " + c);
    d = a.multiply(b.multiply(c));
    e = (a.multiply(b)).multiply(c);

    // System.out.println("d = " + d);
    // System.out.println("e = " + e);

    // System.out.println("d-e = " + d.subtract(c) );

    assertEquals("a(bc) = (ab)c", d, e);
    assertTrue("a(bc) = (ab)c", d.equals(e));

    BigQuaternion x = a.leadingBaseCoefficient().inverse();
    c = a.monic();
    d = a.multiply(x);
    assertEquals("a.monic() = a(1/ldcf(a))", c, d);

    BigQuaternion y = b.leadingBaseCoefficient().inverse();
    c = b.monic();
    d = b.multiply(y);
    assertEquals("b.monic() = b(1/ldcf(b))", c, d);

    e = new GenPolynomial<BigQuaternion>(fac, y);
    d = b.multiply(e);
    assertEquals("b.monic() = b(1/ldcf(b))", c, d);

    // d = e.multiply(b);
    // assertEquals("b.monic() = (1/ldcf(b) (0))*b",c,d);
  }
  /** Test coefficient map function. */
  public void testMap() {
    // integers
    BigInteger rf = new BigInteger();
    // System.out.println("rf = " + rf);

    // polynomials over integral numbers
    GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf, rl);
    // System.out.println("pf = " + pf);

    // random polynomial
    GenPolynomial<BigInteger> p = pf.random(kl, 2 * ll, el, q);
    // System.out.println("p = " + p);

    // test times 1
    GenPolynomial<BigInteger> q;
    q = p.map(new Multiply<BigInteger>(rf.getONE()));
    assertEquals("p == q ", p, q);

    // test times 0
    q = p.map(new Multiply<BigInteger>(rf.getZERO()));
    assertTrue("q == 0 ", q.isZERO());

    // test times -1
    q = p.map(new Multiply<BigInteger>(rf.getONE().negate()));
    assertEquals("p == q ", p.negate(), q);
  }
 /** Test random polynomial. */
 public void testRandom() {
   for (int i = 0; i < 7; i++) {
     a = fac.random(ll);
     // fac.random(rl+i, kl*(i+1), ll+2*i, el+i, q );
     assertTrue("length( a" + i + " ) <> 0", a.length() >= 0);
     assertTrue(" not isZERO( a" + i + " )", !a.isZERO());
     assertTrue(" not isONE( a" + i + " )", !a.isONE());
   }
 }
  /** Test constructors and factory. */
  public void testConstructors() {
    // rational numbers
    BigRational rf = new BigRational();
    // System.out.println("rf = " + rf);

    // BigRational r = rf.fromInteger( 99 );
    // System.out.println("r = " + r);
    // r = rf.random( 9 ).sum(r);
    // System.out.println("r = " + r);
    // assertFalse("r.isZERO() = ", r.isZERO());

    // RingElem<BigRational> re = new BigRational( 3 );
    // System.out.println("re = " + re);
    // rf = (BigRational) re;

    // RingFactory<BigRational> ref = new BigRational( 3 );
    // System.out.println("re = " + re);
    // rf = (BigRational) ref;

    // polynomials over rational numbers
    GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(rf, 2);
    // System.out.println("pf = " + pf);

    GenPolynomial<BigRational> p = pf.getONE();
    // System.out.println("p = " + p);
    p = pf.random(9);
    // System.out.println("p = " + p);
    p = pf.getZERO();
    // System.out.println("p = " + p);

    RingElem<GenPolynomial<BigRational>> pe = new GenPolynomial<BigRational>(pf);
    // System.out.println("pe = " + pe);
    // System.out.println("p.equals(pe) = " + p.equals(pe) );
    // System.out.println("p.equals(p) = " + p.equals(p) );
    assertTrue("p.equals(pe) = ", p.equals(pe));
    assertTrue("p.equals(p) = ", p.equals(p));

    pe = pe.sum(p); // why not p = p.add(pe) ?
    // System.out.println("pe = " + pe);
    assertTrue("pe.isZERO() = ", pe.isZERO());
    p = pf.random(9);
    p = p.subtract(p);
    // System.out.println("p = " + p);
    // System.out.println("p.isZERO() = " + p.isZERO());
    assertTrue("p.isZERO() = ", p.isZERO());

    // polynomials over (polynomials over rational numbers)
    GenPolynomialRing<GenPolynomial<BigRational>> ppf =
        new GenPolynomialRing<GenPolynomial<BigRational>>(pf, 3);
    // System.out.println("ppf = " + ppf);

    GenPolynomial<GenPolynomial<BigRational>> pp = ppf.getONE();
    // System.out.println("pp = " + pp);
    pp = ppf.random(2);
    // System.out.println("pp = " + pp);
    pp = ppf.getZERO();
    // System.out.println("pp = " + pp);

    RingElem<GenPolynomial<GenPolynomial<BigRational>>> ppe =
        new GenPolynomial<GenPolynomial<BigRational>>(ppf);
    // System.out.println("ppe = " + ppe);
    // System.out.println("pp.equals(ppe) = " + pp.equals(ppe) );
    // System.out.println("pp.equals(pp) = " + pp.equals(pp) );
    assertTrue("pp.equals(ppe) = ", pp.equals(ppe));
    assertTrue("pp.equals(pp) = ", pp.equals(pp));

    ppe = ppe.sum(pp); // why not pp = pp.add(ppe) ?
    // System.out.println("ppe = " + ppe);
    assertTrue("ppe.isZERO() = ", ppe.isZERO());
    pp = ppf.random(2);
    pp = pp.subtract(pp);
    // System.out.println("pp = " + pp);
    // System.out.println("pp.isZERO() = " + pp.isZERO());
    assertTrue("pp.isZERO() = ", pp.isZERO());

    // polynomials over (polynomials over (polynomials over rational numbers))
    GenPolynomialRing<GenPolynomial<GenPolynomial<BigRational>>> pppf =
        new GenPolynomialRing<GenPolynomial<GenPolynomial<BigRational>>>(ppf, 4);
    // System.out.println("pppf = " + pppf);

    GenPolynomial<GenPolynomial<GenPolynomial<BigRational>>> ppp = pppf.getONE();
    // System.out.println("ppp = " + ppp);
    ppp = pppf.random(2);
    // System.out.println("ppp = " + ppp);
    ppp = pppf.getZERO();
    // System.out.println("ppp = " + ppp);

    RingElem<GenPolynomial<GenPolynomial<GenPolynomial<BigRational>>>> pppe =
        new GenPolynomial<GenPolynomial<GenPolynomial<BigRational>>>(pppf);
    // System.out.println("pppe = " + pppe);
    // System.out.println("ppp.equals(pppe) = " + ppp.equals(pppe) );
    // System.out.println("ppp.equals(ppp) = " + ppp.equals(ppp) );
    assertTrue("ppp.equals(pppe) = ", ppp.equals(pppe));
    assertTrue("ppp.equals(ppp) = ", ppp.equals(ppp));

    pppe = pppe.sum(ppp); // why not ppp = ppp.add(pppe) ?
    // System.out.println("pppe = " + pppe);
    assertTrue("pppe.isZERO() = ", pppe.isZERO());
    ppp = pppf.random(2);
    ppp = ppp.subtract(ppp);
    // System.out.println("ppp = " + ppp);
    // System.out.println("ppp.isZERO() = " + ppp.isZERO());
    assertTrue("ppp.isZERO() = ", ppp.isZERO());

    // some tests
    // GenPolynomial<BigRational> pfx = new GenPolynomial<BigRational>();
    // System.out.println("pfx = " + pfx);
  }