public class TestSuite
extends Object
This class must contain in import
statement for the classes to be graded
for this assignment. Thus, this class must be compiled.
Methods must be static
Method names must contain the string "test" somewhere in the name, all others are ignored. If a test needs a helper method, then the helper method name should not contain the string "test".
Tests methods are called alphabetically, thus the order they occur in this file is not important.
test_w()
test_b()
b_helper()
a_test()
then they will be run in this order (and output labeled as shown)
a_test() --> Test 1
test_b() --> Test 2
test_w() --> Test 3
Note that b_helper
will not be run (because it doesn't contain the string "test"
in its name. It is recommended, for clarity, to list the methods alphabetically, for example:
test01, test02, etc
Each test method is a test case and contains 1 or more items (parts) to be graded. A test case has a "worth", the number of points the test case is worth. For example, if a test case is worth 10 points and there are 4 parts, then each part is worth 2.5 points. Thus, if a student solution gets 3 of the 4 parts correct for this test case, then they earn 7.5 out of 10 points (More information follows).
ArrayList<String>
. There can be no line breaks (\n)
in any string in the list. Every string in the list must have this format:
Element Contents
----------------
0 Description of test
1 Points this problem is worth
2 Item to be graded
3 Item to be graded
... ...
Thus, each item to be graded is an individual string in the returned list. (More information follows).
r2.compareTo(g1)=-3
r2.getId()=3, g1.getID()=6
Which might be produced by code like this (results
is the list that will be returned):
results.add("r2.compareTo(g1)= " + r2.compareTo(g1));
results.add(String.format("r2.getId()=%d, g1.getId()=%d", r2.getId(), g1.getId()));
The output of the program will show the expected answer and the actual (student) answer side-by-side.
Thus, it is useful to make the items to be graded to read as clear as possible so that a student
can understand (some) of where their program failed. For example, the output of the program might
look like this:
Test 4 - compareTo() and getId()
Incorrect - Expected: r2.compareTo(g1)=-3 | Actual: r2.compareTo(g1)=24
Correct - Expected: r2.getId()=3, g1.getID()=6 | Actual: r2.getId()=3, g1.getID()=4
Summary: 1 out of 2 answers correct: 5.0 points out of 10
String items are graded by string comparison (equals) meaning that the expected answer string
is compared to the actual answer string. It is important to keep that in mind. For example, that is
why you would not want any doubles in such a string as there could be small differences that
don't invalidate a student's answer. For example: x=3.1415926 vs. x=3.1415927. However, there may
be cases where you could include a double rounded to a certain precision. For example, if you
were dealing with currency, you possibly could round so that you were comparing against a string
like this: "total deposits=$123.45". Again, we deal with doubles next.
Finally, the designer of tests will want to be careful as to how many "answers" there are in a string that is being graded, and any dependencies between them so that you don't over-penalize errors. For example, suppose you have a class with methods to calculate the surface area and volume of a 3-d object. If you wanted to weight these differently (different max points for each) you could have two separate test methods, one to test the area, and one to test the volume. Or, it you want the max points to be the same for each, you could have a single test with two parts: one part for the area and one part for the volume.
Math.abs(exp-act)<maxError
. (More on this below). For example, the output of this program for a test
that contains doubles might look like this:
Test: 16-Testing double result
Correct - Expected: Average ID=8.833333333333334 | Actual: Average ID=8.833333333333334
Actual Error=0.0<0.08833333333333333=Max Error
Incorrect - Expected: Average ID=8.833333333333334 | Actual: Average ID=8.333333333333334
Actual Error=0.5>0.01=Max Error
Summary: 1 out of 2 answers correct : 2.5 points out of 5.0
Notice that the results still show the expected and actual strings, but they also show actual
and max error when comparing the doubles. The answer strings that are contained in the return of the
test method would look like this:
%d 8.833333333333334 %tp 1.0 Average ID=8.833333333333334
%d 8.833333333333334 %ta 0.01 Average ID=8.333333333333334
Thus, the format for indicating a double is:
%d value %t[p|a] tol informative_string_with_double
Only one double can be contained in a string. The only thing that is graded is the double itself,
not "informative_string_with_double", this is used for display. Note:
Math.abs(1000-act)<10
is correct. Note, percent is specified
as a percent, not a fraction.
Math.abs(1000-act)<5
is correct.
results.add("%d " + avg + " %tp 1.0 Average ID=" + avg);
results.add("%d " + avg + " %ta 0.01 Average ID=" + avg);
r2.compareTo(g1)=-3
r2.getId()=3, g1.getID()=6
we would use code like this:
try{
results.add("r2.compareTo(g1)= " + r2.compareTo(g1));
}
catch(Exception e) {
results.add(e.toString());
}
try{
results.add(String.format("r2.getId()=%d, g1.getId()=%d", r2.getId(), g1.getId()));
}
catch(Exception e) {
results.add(e.toString());
}
Thus, an expected answer of say: "r2.compareTo(g1)=3" would be compared to the exception string which
of course would be incorrect and having the added bonus of showing that the student code generated
an exception and its type.
Constructor and Description |
---|
TestSuite() |
Modifier and Type | Method and Description |
---|---|
static ArrayList<String> |
test01() |
static ArrayList<String> |
test02() |
static ArrayList<String> |
test03() |