Please send questions to st10@humboldt.edu .

/**
 * Test methods in recursion-conglomerate class RecursionExamples
 * 
 * @Sharon Tuttle
 * @last modified 4-1-03
 */
public class RecursionExamplesTest extends JPFalt
{
    public static void main(String[] args) 
    { 
            new RecursionExamplesTest(); 
    }
    
    /** Test suite for the class RecursionExamplesTest */
    
    /* tests for method sumList() */
    void sumListTest()
    {
        Cs132LinkedList newList = new Cs132LinkedList();
        
        testHeader("sumList()");

        expected(0);
        actual(RecursionExamples.sumList(newList.getHead()));
        
        newList.addFirst(new Integer(30));
        newList.addLast(new Integer(58));
        newList.addLast(new Integer(22));

        expected(110);
        actual(RecursionExamples.sumList(newList.getHead()));
        
        // if remove 30, is sum 58+22?
        try
        {
            newList.remove(0);
        }
        catch (Exception ex) {}
        expected(80);
        actual(RecursionExamples.sumList(newList.getHead()));
        
        // if remove 58, is sum 22?
        try
        {
            newList.remove(0);
        }
        catch (Exception ex) {}
        expected(22);
        actual(RecursionExamples.sumList(newList.getHead()));
        
        // if remove all, is sum again 0?
        try
        {
            newList.remove(0);
        }
        catch (Exception ex) {}
        expected(0);
        actual(RecursionExamples.sumList(newList.getHead()));
    }
    
    /* tests for method binarySearch() */
    void binarySearchTest()
    {
        testHeader("binarySearch()");
        
        int myNums[] = {2, 3, 8, 16, 22, 28, 356, 400, 401, 402};
        
        // look for a "too small" value
        expected(-1);
        actual(RecursionExamples.binarySearch(myNums, 0));

        // look for a "too big" value
        expected(-1);
        actual(RecursionExamples.binarySearch(myNums, 403));
        
        // look for a "middle" value NOT in array
        expected(-1);
        actual(RecursionExamples.binarySearch(myNums, 188));
        
        // look for FIRST element
        expected(0);
        actual(RecursionExamples.binarySearch(myNums, 2));
        
        // look for LAST element
        expected(9);
        actual(RecursionExamples.binarySearch(myNums, 402));
        
        // look for an element that IS within
        expected(6);
        actual(RecursionExamples.binarySearch(myNums, 356));
    }
    
    // tests of solveTowers() method
    void solveTowersMethod()
    {
        testHeader("solveTowers()");
    
        RecursionExamples anchor = new RecursionExamples();
    
        expected("Move top disk on pole A to pole B");
        actual("instructions follow:");
        anchor.solveTowers(1, 'A', 'B', 'C');
        
        println("");
        println("try the following instructions: do they work?");
        anchor.solveTowers(2, 'A', 'B', 'C');
        
        println("");
        println("try the following instructions: do they work?");
        anchor.solveTowers(3, 'A', 'B', 'C');
        
        println("");
        println("try the following instructions: do they work?");
        anchor.solveTowers(4, 'A', 'B', 'C');
    }
}