// Approach 1: Testing Shell

// a ComparisonChecker1 object is used to compare the output of the 
// student's program to that of the instructor's program

import OutputFormatter1;

public class ComparisonChecker1 {

    int userNumber, authorityNumber;
    int testLevel = -1;
    boolean comparisonResults;
    String userResults;
    String authorityResults;
    OutputFormatter1 out;
    SimpleOutput simpOut;

/////////////////
// Constructor //
/////////////////

// ComparisonChecker1 needs an OutputFormatter object and an integer 
// telling it what level of correctness to check for.  0 corresponds
// to exactly matching outputs, 1 corresponds to outputs that match by 
// line, and 2 corresponds to outputs that match when whitespace is 
// disregarded entirely

    public ComparisonChecker1(OutputFormatter1 here, int correctnessLevel){
        out = here;
	testLevel = correctnessLevel;
        simpOut = new SimpleOutput();
    }

// if no testLevel is specified, 0 is used
    public ComparisonChecker1(OutputFormatter1 here){
        out = here;
	testLevel = 0;
        simpOut = new SimpleOutput();
    }

/////////////
// methods //
/////////////

// setUserResults  
public void setUserResults(String user, int testNumber) {
    simpOut.println ("ComparisonChecker1::setUserResults called with parameters:");
    simpOut.println ("     user output:  " + user);
    simpOut.println ("     test number:  " + testNumber);
       userResults = user;
       userNumber = testNumber;
       if (authorityNumber == userNumber) 
          this.compare();
}


// setAuthorityResults
public void setAuthorityResults(String authority, int testNumber) {
    simpOut.println ("ComparisonChecker1::setAuthorityResults called with parameters:");
    simpOut.println ("     authority output:  " + authority);
    simpOut.println ("     test number:  " + testNumber);
       authorityResults = authority;
       authorityNumber = testNumber;
       if (authorityNumber == userNumber) 
          this.compare();
}

private void compare(){

    if (authorityNumber == 2) {
        simpOut.println ("ComparisonChecker1 result forwarded as passed test");
        out.getComp(true, userResults, authorityResults);
    }
    else {
        simpOut.println ("ComparisonChecker1 result forwarded as failed test");
        out.getComp(false, userResults, authorityResults);
    }
     
} // compare()

}

