JavaLib
 
Tester
 
Overview
Basic Types
User Types
Inexact Values
Sets
Iterable
Traversals
Maps
Random Choice
Range Check
Equivalence
ISame
Exceptions
Constructors
Methods
CheckFail
 
Sources
Downloads
 
TSRJ Home
TSRJ Local

Traversals

The tester recognizes an additional interface that provides methods for traversing over the elements of a data structure. This is a functional iterator used with our students that is defined as follows:

/** An interface that defines a functional iterator 
  *  for traversing datasets */
public interface Traversal<T> {

   /** return true if the dataset is empty */
   public boolean isEmpty();

   /** return the first element if available - 
     *  otherwise throw an exception */
   public T getFirst();

   /** return the rest of this dataset if available - 
     *  otherwise throw an exception */
   public Traversal<T>getRest();
}
If the user implements the Traversal interface for his own class, the checkExpect still examines the data within the class by comparing the values of the corresponding fields. To invoke the comparison of the data generated by the Traversal iterator, the user needs to use the checkTraversal (or the inexact variant, the checkInexactTraversal) method. The same examples that have been used for the checkIterable are applicable here:
  tree1:                    tree2:

     7                        4
   /   \                    /   \
  4     9                  *     9
 / \   / \                      / \
*   * *   *                    7   *
                              / \
                             *   *
The test cases would be:
void testTrees(Tester t){
  t.checkExpect(tree1, tree2, "should fail");
  t.checkTraversal(tree1, tree2, "should succeed");
}

Example Traversals tests


Code sources

Here 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 2011generated with DrRacket