public class PolynomialChecker
{
  public static void main(String[] args)
  {
    int errorCount = 0;
    
    double[] coeffs = new double[7];
    coeffs[0] = 2.0;
    coeffs[1] = 5.0;
    coeffs[2] = 0;
    coeffs[3] = 0;
    coeffs[4] = 1.0;
    coeffs[5] = 0;
    coeffs[6] = 0;
    
    System.out.println("Starting PolynomialChecker...");
    System.out.println("...");
    System.out.println("");
    
    System.out.println("Creating a Polynomial, P1, with coefficients 2,5,0,0,1,0,0");
    System.out.println("...");
    Polynomial p = new Polynomial(coeffs);
    System.out.println("");
    
    System.out.println("Checking P1 degree");
    System.out.println("...");
    int deg = p.getDegree();
    if(deg != 4)
    {
      errorCount++;
      System.out.println("ERROR: getDegree returned " + deg + " instead of 4");
    }
    System.out.println("");
    
    System.out.println("Evaluating P1 at x=3.5");
    System.out.println("...");
    double ans = p.evaluate(3.5);
    if(Math.abs(ans - 169.5625) > .0002)
    {
      errorCount++;
      System.out.println("ERROR: evaluation returned " + ans + " instead of 169.5625");
    }
    System.out.println("");
    
    double[] coeffs2 = new double[11];
    coeffs2[0] = 2.0;
    coeffs2[1] = 5.0;
    coeffs2[2] = 0;
    coeffs2[3] = 0;
    coeffs2[4] = 1.0;
    coeffs2[5] = 0;
    coeffs2[6] = 0;
    coeffs2[7] = 0;
    coeffs2[8] = 0;
    coeffs2[9] = 0;
    coeffs2[10] = 0;
    
    System.out.println("Creating a Polynomial, P2, with coefficients 2,5,0,0,1,0,0,0,0,0,0");
    System.out.println("...");
    Polynomial p2 = new Polynomial(coeffs2);
    System.out.println("");
    
    System.out.println("Comparing P2 with P1 (should be the same)");
    System.out.println("...");
    boolean comp = p.equals(p2);
    boolean comp2 = p2.equals(p);
    if(comp == false)
    {
      errorCount++;
      System.out.println("ERROR: calling P1.equals(P2) returned false");
    }
    if(comp2 == false)
    {
      errorCount++;
      System.out.println("ERROR: calling P2.equals(P1) returned false");
    }
    System.out.println("");
    
    double[] coeffs3 = new double[7];
    coeffs3[0] = 1.0;
    coeffs3[1] = 0;
    coeffs3[2] = 2;
    coeffs3[3] = 5.0;
    coeffs3[4] = 1;
    coeffs3[5] = 0;
    coeffs3[6] = 0;
    
    System.out.println("Creating a Polynomial, P3, with coefficients 1,0,2,5,1,0,0");
    System.out.println("...");
    Polynomial p3 = new Polynomial(coeffs3);
    System.out.println("");
    
    System.out.println("Comparing P3 with P1 (should be different)");
    System.out.println("...");
    comp = p.equals(p3);
    comp2 = p3.equals(p);
    if(comp == true)
    {
      errorCount++;
      System.out.println("ERROR: calling P1.equals(P3) returned true");
    }
    if(comp2 == true)
    {
      errorCount++;
      System.out.println("ERROR: calling P3.equals(P1) returned true");
    }
    System.out.println("");
    
    double[] coeffs4 = new double[2];
    coeffs[0] = 0;
    coeffs[1] = 0;
    
    System.out.println("Creating a Polynomial, P4, with coefficients 0,0");
    System.out.println("...");
    Polynomial p4 = new Polynomial(coeffs4);
    System.out.println("");
    
    System.out.println("Checking that P4 has degree 0");
    System.out.println("...");
    deg = p4.getDegree();
    if(deg != 0)
    {
      errorCount++;
      System.out.println("ERROR: P4 returned degree " + deg + " instead of 0");
    }
    System.out.println("");
    
    System.out.println("Comparing P4 with P1 (should be different)");
    System.out.println("...");
    comp = p.equals(p4);
    comp2 = p4.equals(p);
    if(comp == true)
    {
      errorCount++;
      System.out.println("ERROR: calling P1.equals(P4) returned true");
    }
    if(comp2 == true)
    {
      errorCount++;
      System.out.println("ERROR: calling P4.equals(P1) returned true");
    }
    System.out.println("");
    
    System.out.println(errorCount + " errors reported");
  }
}