| Basic Types | |||||||||||||||||||||||||||
The tester allows comparison of pairs of all primitive types, or pairs of objects that are instances
of the same wrapper class. An instance if a primitive type can be compared to an instance of its corresponding
wrapper class as well. The tester first converts the
values to the corresponding primitive type, then uses the Java Sample test cases would be:
boolean testPrimitive(Tester t){
t.checkExpect(5, new Integer(5), "should succeed");
t.checkExpect(5, 5, "should succeed");
t.checkExpect(new Long(5), new Integer(5), "should fail");
}
The comparison of inexact numbers (of the types Inexact numbers (
(Math.abs(val1 - val2) / (Math.max (Math.abs(val1), Math.abs(val2))))
< TOLERANCE;
So, we can have two tests that compare the same objects, where one test succeeds and the other fails:
boolean testDouble(Tester t){
t.checkExpect(0.003, 0.00298, 0.001, "should succeed");
t.checkExpect(0.003, 0.00298, 0.01, "should fail");
}
If the comparison of two objects involves a comparison of inexact numbers, the test case report contains a warning, regardless whether the test succeeds or fails, regardless whether the programmer requested the inexact comparison, or failed to do so. Please, see the section on Inexact Values for further details, especially what happens if the two values match exactly, and how the comparison with exact zero is handled. All tests that request exact comparison, but require inexact comparison of any fields will fail. The classes that represent big numbers The comparison of The description of the equality testing of instances of the If both data values are Code sourcesHere is the complete source code for this test suite. You can also download the entire souce code as a zip file. Complete test results are shown here. | ||||||||||||||||||||||||||||
| last updated on Mon Apr 4 15:26:25 EDT 2011 | generated with DrRacket |