| 28 |
irasnyd |
1 |
// Written by Ira Snyder
|
|
|
2 |
// Due Date: 11-15-2004
|
|
|
3 |
// Project #3
|
|
|
4 |
import java.io.*;
|
|
|
5 |
|
|
|
6 |
class Driver {
|
| 29 |
irasnyd |
7 |
public static void main ( String [] args ) throws Exception {
|
|
|
8 |
|
|
|
9 |
System.out.println( test_12_2() );
|
| 31 |
irasnyd |
10 |
System.out.println( test_12_3() );
|
|
|
11 |
System.out.println( test_12_4() );
|
|
|
12 |
System.out.println( test_12_5() );
|
|
|
13 |
|
| 29 |
irasnyd |
14 |
} //end main
|
| 28 |
irasnyd |
15 |
|
| 30 |
irasnyd |
16 |
public static BinaryTree createTestTree() {
|
| 29 |
irasnyd |
17 |
BinaryTree treeB = new BinaryTree("B");
|
|
|
18 |
BinaryTree treeD = new BinaryTree("D");
|
|
|
19 |
BinaryTree treeE = new BinaryTree("E");
|
|
|
20 |
BinaryTree treeC = new BinaryTree("C",treeD,treeE);
|
|
|
21 |
BinaryTree treeA = new BinaryTree("A",treeB,treeC);
|
|
|
22 |
|
| 30 |
irasnyd |
23 |
return treeA;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public static String test_12_2() {
|
|
|
27 |
BinaryTree treeA = createTestTree();
|
|
|
28 |
|
| 29 |
irasnyd |
29 |
String experimentalResult = treeA.toString();
|
|
|
30 |
String correctResult = "((B),A,((D),C,(E)))";
|
|
|
31 |
|
| 30 |
irasnyd |
32 |
if( correctResult.equals(experimentalResult) )
|
|
|
33 |
return "test_12_2: PASSED";
|
|
|
34 |
|
|
|
35 |
return "test_12_2: *** FAILED ***";
|
| 29 |
irasnyd |
36 |
}
|
| 31 |
irasnyd |
37 |
|
|
|
38 |
public static String test_12_3() {
|
|
|
39 |
BinaryTree treeA = createTestTree();
|
|
|
40 |
BinaryTree treeAleft = treeA.getLeft();
|
| 29 |
irasnyd |
41 |
|
| 31 |
irasnyd |
42 |
if( treeA.isLeaf() == false && treeAleft.isLeaf() == true )
|
|
|
43 |
return "test_12_3: PASSED";
|
| 29 |
irasnyd |
44 |
|
| 31 |
irasnyd |
45 |
return "test_12_3: *** FAILED ***";
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public static String test_12_4() {
|
|
|
49 |
BinaryTree treeA = createTestTree();
|
|
|
50 |
int correctResult = 5;
|
|
|
51 |
int experimentalResult = treeA.size();
|
|
|
52 |
|
|
|
53 |
if( correctResult == experimentalResult )
|
|
|
54 |
return "test_12_4: PASSED";
|
|
|
55 |
|
|
|
56 |
return "test_12_4: *** FAILED ***";
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public static String test_12_5() {
|
|
|
60 |
BinaryTree treeA = createTestTree();
|
|
|
61 |
int correctResult = 2;
|
|
|
62 |
int experimentalResult = treeA.height();
|
|
|
63 |
|
|
|
64 |
if( correctResult == experimentalResult )
|
|
|
65 |
return "test_12_5: PASSED";
|
|
|
66 |
|
|
|
67 |
return "test_12_5: *** FAILED ***";
|
|
|
68 |
}
|
|
|
69 |
|
| 28 |
irasnyd |
70 |
} //end class Driver
|
|
|
71 |
|
|
|
72 |
/*
|
|
|
73 |
BufferedReader kb = new BufferedReader(
|
|
|
74 |
new InputStreamReader(System.in));
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
BufferedReader br = new BufferedReader(
|
|
|
78 |
new InputStreamReader(
|
|
|
79 |
new FileInputStream(filename)));
|
|
|
80 |
|
|
|
81 |
PrintStream ps = new PrintStream(
|
|
|
82 |
new FileOutputStream(
|
|
|
83 |
new File(filename)));
|
|
|
84 |
|
|
|
85 |
*/
|
|
|
86 |
|