| Iterable | |||||||||||||||||||||||||||
The tester has a special way of comparing elements of a collection that implements
the However, if the user implements the A compelling example of this scenario is when we wish to compare two recursively-built binary search trees, the first time verifying the shape of the tree, the second time wanting to see that both contain the same collection od elements, even if their shapes may differ. So, the following two trees will fail the first test, but pass the second one, assuming the iterator traverses the tree inorder:
tree1: tree2:
7 4
/ \ / \
4 9 * 9
/ \ / \ / \
* * * * 7 *
/ \
* *
The test cases would be:
void testTrees(Tester t){
t.checkExpect(tree1, tree2, "should fail");
t.checkIterable(tree1, tree2, "should succeed");
}
Two Arrays are similarly compared by making sure they contain the same number and types of items and every pair of corresponding items passes the equality test. 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:34:55 EDT 2011 | generated with DrRacket |