class Test
extends Object
Test
class represents the results of a single test case. A test case can
have multiple parts (answers) to be evaluated where each part is stored as an entry in
actualOutput
. There is an assess
method that compares the actual
and expected output. A test case has a maximum number of points, pointsMax
. The
assess
method determines the numCorrect
parts which is used to
compute the pointsEarned
. The class also keeps track of which parts are correct
with isCorrect
. toString
returns a report of this test case showing
expeced and actual output, wether correct, points earned, etc.
expectedOutput
and actualOutput
and can have multiple parts to beModifier and Type | Field and Description |
---|---|
(package private) List<String> |
actualOutput |
(package private) String |
description |
(package private) List<String> |
expectedOutput |
(package private) boolean |
hasRunTimeError |
(package private) List<Boolean> |
isCorrect |
(package private) int |
numCorrect |
(package private) int |
numTotal |
(package private) double |
pointsEarned |
(package private) double |
pointsMax |
Constructor and Description |
---|
Test() |
Modifier and Type | Method and Description |
---|---|
void |
addActualOutput(ArrayList<String> results)
Adds the actual output.
|
void |
assess()
Grades this test case.
|
private void |
assessDouble(String exp,
String act)
Compares an expected double result to an actual double result using a tolerance
|
private void |
assessString(String exp,
String act)
Compares the expected and actual output of a part of a test case using string equality.
|
private void |
compareExpAndActOutputSizes() |
private double |
getActError(String exp,
String act)
Computes the actual error between the expected double and the actual double.
|
private double |
getDouble(String output)
Extracts the double from the
output string. |
private double |
getMaxError(String output)
Computes the maximum error that is allowed.
|
private boolean |
hasDoubleResult(String exp) |
private void |
initializeInstanceVars() |
private String |
stripDouble(String output)
Removes the double and tolerance from
output and returns just the output string
containing the double. |
String |
toString()
Returns a summary of this test case showing expected and actual results for each part as well
as correctness, number correct, and points earned.
|
String description
double pointsMax
double pointsEarned
int numCorrect
int numTotal
List<String> expectedOutput
List<String> actualOutput
List<Boolean> isCorrect
boolean hasRunTimeError
public void addActualOutput(ArrayList<String> results)
results
- The results of an actual test case. Includes the description and maximum
points.public void assess()
expectedOutput
and actualOutput
must be
the same size, if not a runtime exception is thrown. Each entry in expectedOutput
and actualOutput
are compared on a one-to-one basis to determine wether the
actualOutput is correct. There are two types of output: (1) string output that can contain
characters, integers, and booleans (2) string output that also contains a double. These two
types are handled differently. Strings are assessed with string equality where doubles are
assessed using a tolerance to allow for slightly different results.private void compareExpAndActOutputSizes()
private void initializeInstanceVars()
private boolean hasDoubleResult(String exp)
private void assessString(String exp, String act)
exp
- The expected output for a part of a test case.act
- The actual output for a part of a test case.private void assessDouble(String exp, String act)
exp
- The expected output for a part of a test case.act
- The actual output for a part of a test case.private double getActError(String exp, String act)
exp
- act
- private double getDouble(String output)
output
string. The format of output
is: %d double_value ...". Thus, output
is split on " " and the second element
is the double.output
- private double getMaxError(String output)
output
is: "%d double_value %t[p|a] tol ...". Thus, split on " " and the
second element is the double, the third is the type of tolerance, and the fourth is the
tolerance value.output
- public String toString()
toString
in class Object
private String stripDouble(String output)
output
and returns just the output string
containing the double. The full format of output
is:
%d double_value %t[p|a] tol output_that_contains_chars_etc_with_double_embeddedoutput
-