Programming and Problem Solving with Java

(やまだぃちぅ) #1

CASE STUDY


508


// Instantiate the key and student sheet objects
key = newAnswerSheet(numItems);
studentSheet = newAnswerSheet(numItems);

// Read values into the key and student answer sheet objects
key.input(inFile);
studentSheet.input(inFile);

while(studentSheet.moreData())
// Compare student answer sheets to the key and print
// results until end of file
{
outFile.println(studentSheet.knowName() + “: number correct “ +
studentSheet.numOfMatches(key));
studentSheet.input(inFile);
}

inFile.close();
outFile.close();
}
}

Testing:This application has one class and a driver. In the past we have used the word
“driver” to refer to a simple application class that is used to test a method. Here we are
using it in its other context: the main class in an object-oriented design. The driver in
this Case Study is class GradeExams, the class that contains the mainmethod. Actually,
these two definitions are not dissimilar. In both cases, the driver starts the process. In a
regular application, the driver implements the top-level algorithm, which might start
any process. In a test driver, the process is always the same because its role is strictly
to test one or more methods.
Does this mean that we need to design a test driver for this application and import
class GradeExams? No, quite the contrary. We can let GradeExams test itself by
carefully choosing our data sets. That is, we can use a black-box testing strategy.
There are three kinds of input to the application: an integer that specifies the num-
ber of questions, a sequence of T’s and F’s that represent the key and a student’s
answers, and a string that represents a student’s name. For the moment, let’s assume
that the data are correct on the file, and instead concentrate on the main processing:
the comparison of the key and a student exam. The following cases come immediately
to mind.
1.the key and the student responses match completely (all are correct)
2.the key and the student responses do not match at all (all are wrong)
3.the key and the student responses partially match (some are correct)
Free download pdf