Rev 33 | Rev 35 | Go to most recent revision | Blame | Compare with Previous | 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() );
System.out.println( test_12_10());
//System.out.println( test_12_11());
BinaryTree treeA = createTestTree();
//System.out.println("level E: " + treeA.level("E"));
//System.out.println("treeA == treeB: " +
// treeA.equals( new BinaryTree("Q",createTestTree(),createTestTree())));
System.out.print("PreOrder: "); BinaryTree.preOrderPrint(treeA);
System.out.println();
System.out.print("PostOrder: "); BinaryTree.postOrderPrint(treeA);
System.out.println();
System.out.print("LevelOrder: "); BinaryTree.levelOrderPrint(treeA);
System.out.println();
System.out.print("InOrder: "); BinaryTree.inOrderPrint(treeA);
System.out.println();
} //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 ***";
}
public static String test_12_10() {
BinaryTree treeA = createTestTree();
if( treeA.isBalanced() == true ) { return "test_12_10: PASSED"; }
return "test_12_10: *** FAILED ***";
}
//public static String test_12_11() {
// BinaryTree treeA = createTestTree();
//
// if( treeA.pathLength() == 6 ) { return "test_12_11: PASSED"; }
// return "test_12_11: *** FAILED *** val:" + treeA.pathLength();
//}
} //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)));
*/