Subversion Repositories programming

Rev

Rev 32 | Blame | Last modification | View Log | RSS feed

// Written by Ira Snyder
// Due Date: 11-15-2004
// Project #3
import java.io.*;

class Driver {
    public static void main ( String [] args ) throws Exception {
    
        System.out.println( test_12_2() );
        System.out.println( test_12_3() );
        System.out.println( test_12_4() );
        System.out.println( test_12_5() );
        System.out.println( test_12_6() );
        System.out.println( test_12_7() );
        System.out.println( test_12_8() );
        System.out.println( test_12_9() );

    } //end main

    public static BinaryTree createTestTree() {
        BinaryTree treeB = new BinaryTree("B");
        BinaryTree treeD = new BinaryTree("D");
        BinaryTree treeE = new BinaryTree("E");
        BinaryTree treeC = new BinaryTree("C",treeD,treeE);
        BinaryTree treeA = new BinaryTree("A",treeB,treeC);
        
        return treeA;
    }

    public static String test_12_2() {
        BinaryTree treeA = createTestTree();
        
        String experimentalResult = treeA.toString();
        String correctResult = "((B),A,((D),C,(E)))";

        if( correctResult.equals(experimentalResult) )
            return "test_12_2: PASSED";

        return "test_12_2: *** FAILED ***";
    }
    
    public static String test_12_3() {
        BinaryTree treeA = createTestTree();
        BinaryTree treeAleft = treeA.getLeft();

        if( treeA.isLeaf() == false && treeAleft.isLeaf() == true )
            return "test_12_3: PASSED";

        return "test_12_3: *** FAILED ***";
    }

    public static String test_12_4() {
        BinaryTree treeA = createTestTree();
        int correctResult = 5;
        int experimentalResult = treeA.size();

        if( correctResult == experimentalResult )
            return "test_12_4: PASSED";

        return "test_12_4: *** FAILED ***";
    }

    public static String test_12_5() {
        BinaryTree treeA = createTestTree();
        int correctResult = 2;
        int experimentalResult = treeA.height();

        if( correctResult == experimentalResult )
            return "test_12_5: PASSED";

        return "test_12_5: *** FAILED ***";
    }

    public static String test_12_6() {
        BinaryTree treeA = createTestTree();
        
        if( treeA.contains("B") &&
            treeA.contains("A") &&
            treeA.contains("D") &&
           !treeA.contains("Z") ) return "test_12_6: PASSED";

        return "test_12_6: *** FAILED ***";
    }

    public static String test_12_7() {
        BinaryTree treeA = createTestTree();
        int correctResult = 3;

        if( correctResult == treeA.numLeaves() )
            return "test_12_7: PASSED";

        return "test_12_7: *** FAILED ***";
    }
    
    public static String test_12_8() {
        BinaryTree treeA = createTestTree();
        BinaryTree tree = new BinaryTree("E",treeA,new BinaryTree("E"));

        int correctResult = 3;
        
        if( correctResult == tree.count("E") )
            return "test_12_8: PASSED";

        return "test_12_8: *** FAILED ***";
    }

    public static String test_12_9() {
        BinaryTree treeA = createTestTree();

        if( treeA.isFull() == false ) { return "test_12_9: PASSED"; }
        return "test_12_9: *** FAILED ***";
    }

} //end class Driver

/*
      BufferedReader kb = new BufferedReader(
                              new InputStreamReader(System.in));


      BufferedReader br = new BufferedReader(
                              new InputStreamReader(
                                  new FileInputStream(filename)));

      PrintStream ps = new PrintStream(
                           new FileOutputStream(
                               new File(filename)));

*/