| CheckFail | |||||||||||||||||||||||||||
At times the user may want to set up a test that verify that the actual value differs from
the expected value. The tester supports this version of tests with the
Here is a simple example of its use:
public class Song{
protected String title;
private int time; // the playing time
public Song(String title, int time){
this.title=title;
this.time=time;
}
// Produce a new song with the same title, but decreased time
public Song changedTime(int dec){
return new Song(this.title, this.time - dec;
}
}
// Tests:
class Examples{
Song song1 = new Song("title1", 4);
Song song2 = new Song("title2", 2);
public void testMethods(Tester t){
// make sure the time has been changed...
t.checkFail(song1.changedTime(2), song1);
}}
A similar variant can be used to verify that an inexact comparison fails. The method
Caution: The test Here are examples of its use: // test should succeed: t.checkInexact(123000.0, 128000.0, 0.1); // test should fail: t.checkInexactFail(123000.0, 128000.0, 0.1); // test should fail: t.checkInexact(143000.0, 128000.0, 0.1); // test should succeed: t.checkInexactFail(143000.0, 128000.0, 0.1); // test should fail (comparing exact values): t.checkInexact(123000, 128000, 0.1); // test should succeed (comparing exact values): t.checkInexactFail(123000, 128000, 0.1); The last two cases will produce the messages: Attempt to make inexact comparison of exact primitive or wrapper data. and Test failed because we cannot make inexact comparison of exact primitive or wrapper data. Code sources
Tests for Here is the source code for this test suite. You can also download the entire souce code as a zip file. Complete test results are shown here.
Tests for Here is the 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:46:34 EDT 2011 | generated with DrRacket |