/** Test Trinks7 GBase. */
  public void testTrinks7GBase() {
    String exam =
        "(B,S,T,Z,P,W) L "
            + "( "
            + "( 45 P + 35 S - 165 B - 36 ), "
            + "( 35 P + 40 Z + 25 T - 27 S ), "
            + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), "
            + "( - 9 W + 15 T P + 20 S Z ), "
            + "( P W + 2 T Z - 11 B**3 ), "
            + "( 99 W - 11 B S + 3 B**2 ), "
            + "( B**2 + 33/50 B + 2673/10000 ) "
            + ") ";
    Reader source = new StringReader(exam);
    GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source);
    try {
      F = parser.nextPolynomialSet();
    } catch (ClassCastException e) {
      fail("" + e);
    } catch (IOException e) {
      fail("" + e);
    }
    // System.out.println("F = " + F);

    G = bbpar.GB(F.list);
    assertTrue("isGB( GB(Trinks7) )", bbpar.isGB(G));
    assertEquals("#GB(Trinks7) == 6", 6, G.size());
    PolynomialList<BigRational> trinks = new PolynomialList<BigRational>(F.ring, G);
    // System.out.println("G = " + trinks);

  }
  /** Test compare sequential with parallel GBase. */
  public void testSequentialParallelGBase() {

    List<GenPolynomial<BigRational>> Gs, Gp;

    L = new ArrayList<GenPolynomial<BigRational>>();

    a = fac.random(kl, ll, el, q);
    b = fac.random(kl, ll, el, q);
    c = fac.random(kl, ll, el, q);
    d = fac.random(kl, ll, el, q);
    e = d; // fac.random(kl, ll, el, q );

    if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
      return;
    }

    L.add(a);
    Gs = bbseq.GB(L);
    Gp = bbpar.GB(L);

    assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp));
    assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs));

    L = Gs;
    L.add(b);
    Gs = bbseq.GB(L);
    Gp = bbpar.GB(L);

    assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp));
    assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs));

    L = Gs;
    L.add(c);
    Gs = bbseq.GB(L);
    Gp = bbpar.GB(L);

    assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp));
    assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs));

    L = Gs;
    L.add(d);
    Gs = bbseq.GB(L);
    Gp = bbpar.GB(L);

    assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp));
    assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs));

    L = Gs;
    L.add(e);
    Gs = bbseq.GB(L);
    Gp = bbpar.GB(L);

    assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp));
    assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs));
  }
  /** Test Trinks7 GBase, syz pair list. */
  @SuppressWarnings("cast")
  public void testTrinks7GBaseSyz() {
    GroebnerBase<BigRational> bbs;
    bbs =
        new GroebnerBaseSeqIter<BigRational>(
            new ReductionSeq<BigRational>(), new OrderedSyzPairlist<BigRational>());

    String exam =
        "(B,S,T,Z,P,W) L "
            + "( "
            + "( 45 P + 35 S - 165 B - 36 ), "
            + "( 35 P + 40 Z + 25 T - 27 S ), "
            + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), "
            + "( - 9 W + 15 T P + 20 S Z ), "
            + "( P W + 2 T Z - 11 B**3 ), "
            + "( 99 W - 11 B S + 3 B**2 ), "
            + "( B**2 + 33/50 B + 2673/10000 ) "
            + ") ";
    @SuppressWarnings("unused")
    String exam2 =
        "(x,y,z) L "
            + "( "
            + "( z y**2 + 2 x + 1/2 )"
            + "( z x**2 - y**2 - 1/2 x )"
            + "( -z + y**2 x + 4 x**2 + 1/4 )"
            + " )";

    Reader source = new StringReader(exam);
    GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source);
    try {
      F = (PolynomialList<BigRational>) parser.nextPolynomialSet();
    } catch (ClassCastException e) {
      fail("" + e);
    } catch (IOException e) {
      fail("" + e);
    }
    // System.out.println("F = " + F);

    G = bbs.GB(F.list);
    assertTrue("isGB( GB(Trinks7) )", bbs.isGB(G));
    assertEquals("#GB(Trinks7) == 6", 6, G.size());
    // PolynomialList<BigRational> trinks = new PolynomialList<BigRational>(F.ring,G);
    // System.out.println("G = " + trinks);
    assertTrue("isGB( GB(Trinks7) )", bb.isGB(G));

    // Reduction<BigRational> rd = new ReductionSeq<BigRational>();
    // System.out.println("G.contains(F) = " + rd.normalform(G,F.list) );
  }
  /** Test parallel GBase. */
  public void testParallelGBase() {

    L = new ArrayList<GenPolynomial<BigRational>>();

    a = fac.random(kl, ll, el, q);
    b = fac.random(kl, ll, el, q);
    c = fac.random(kl, ll, el, q);
    d = fac.random(kl, ll, el, q);
    e = d; // fac.random(kl, ll, el, q );

    if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
      return;
    }

    assertTrue("not isZERO( a )", !a.isZERO());
    L.add(a);

    L = bbpar.GB(L);
    assertTrue("isGB( { a } )", bbpar.isGB(L));

    assertTrue("not isZERO( b )", !b.isZERO());
    L.add(b);
    // System.out.println("L = " + L.size() );

    L = bbpar.GB(L);
    assertTrue("isGB( { a, b } )", bbpar.isGB(L));

    assertTrue("not isZERO( c )", !c.isZERO());
    L.add(c);

    L = bbpar.GB(L);
    assertTrue("isGB( { a, b, c } )", bbpar.isGB(L));

    assertTrue("not isZERO( d )", !d.isZERO());
    L.add(d);

    L = bbpar.GB(L);
    assertTrue("isGB( { a, b, c, d } )", bbpar.isGB(L));

    assertTrue("not isZERO( e )", !e.isZERO());
    L.add(e);

    L = bbpar.GB(L);
    assertTrue("isGB( { a, b, c, d, e } )", bbpar.isGB(L));
  }