| Range Check | |||||||||||||||||||||||||||
At times we just want to make sure the expected value falls within the given range. The tester supports three variants of such range checks. For every variant the programmer supplies the expected value and the lower and upper bounds for the desired range. Additional arguments may specify whether the bounds are inclusive or exclusive (see below). The first variant, the method
t.checkNumRange(5, 0, 4.9, "fails");
t.checkNumRange(5, 0, 5.0, false, true,
"succeeds: inclusive upper bound");
t.checkNumRange(0.0, 0, 5.0, false, true,
"fails: exclusive lower bound");
The second variant the method The third variant, the method In all three variants, by default, the test uses the inclusive lower bound and the exclusive upper bound . The user may supply two additional boolean values that determine whether the lower bound and the upper bound should be inclusive. The following example illustrates the use of the
public void testReply(Tester t){
String aaa = "aaa";
String abc1 = "abc";
String abc2 = "abc";
String bcd = "bcd";
String cde = "cde";
String cde2 = "cde";
String def = "def";
t.checkRange(aaa, abc1, cde,
"fails: aaa is below low: [abc cde)");
t.checkRange(abc2, abc1, cde,
"abc is equal low: [abc cde)");
t.checkRange(abc2, abc1, cde, false, true,
"abc is equal low: [abc cde)");
t.checkRange(bcd, abc1, cde,
"bcd is within range: [abc cde)");
t.checkRange(cde, abc1, cde,
"fails: cde equals high: [abc cde)");
t.checkRange(cde, abc1, cde, true, true,
"succeedss: cde equals high: [abc cde)");
t.checkRange(def, abc1, cde,
"fails def is above high: [abc cde)");
Book p = new Book("Pearl", "JS");
Book c = new Book("Cosmos", "CS");
Book h = new Book("Hamlet", "WS");
t.checkRange(h, c, p,
new Comparator<Book>(){
public int compare(Book b1, Book b2){
return b1.title.compareTo(b2.title);
}}, "Hamlet between Cosmos and Pearl");
}
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 |