Subversion Repositories programming

Rev

Rev 34 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34 Rev 35
Line 4... Line 4...
4
import java.io.*;
4
import java.io.*;
5
 
5
 
6
class Driver {
6
class Driver {
7
    public static void main ( String [] args ) throws Exception {
7
    public static void main ( String [] args ) throws Exception {
8
    
8
    
-
 
9
    }
-
 
10
 
-
 
11
    public static void run_BinaryTree_tests() {
9
        System.out.println( test_12_2() );
12
        System.out.println( test_12_2() );
10
        System.out.println( test_12_3() );
13
        System.out.println( test_12_3() );
11
        System.out.println( test_12_4() );
14
        System.out.println( test_12_4() );
12
        System.out.println( test_12_5() );
15
        System.out.println( test_12_5() );
13
        System.out.println( test_12_6() );
16
        System.out.println( test_12_6() );
14
        System.out.println( test_12_7() );
17
        System.out.println( test_12_7() );
15
        System.out.println( test_12_8() );
18
        System.out.println( test_12_8() );
16
        System.out.println( test_12_9() );
19
        System.out.println( test_12_9() );
17
        System.out.println( test_12_10());
20
        System.out.println( test_12_10());
18
        //System.out.println( test_12_11());
21
        System.out.println( test_12_11());
19
        
-
 
20
        BinaryTree treeA = createTestTree();
-
 
21
        //System.out.println("level E: " + treeA.level("E"));
22
        System.out.println( test_12_12());
22
        //System.out.println("treeA == treeB: " + 
23
        System.out.println( test_12_13());
23
        //    treeA.equals( new BinaryTree("Q",createTestTree(),createTestTree())));
-
 
24
        
-
 
25
        System.out.print("PreOrder: "); BinaryTree.preOrderPrint(treeA); 
-
 
26
        System.out.println();
24
        System.out.println( test_12_14());
27
        
-
 
28
        System.out.print("PostOrder: "); BinaryTree.postOrderPrint(treeA);
-
 
29
        System.out.println();
25
        System.out.println( test_12_15());
30
        
-
 
31
        System.out.print("LevelOrder: "); BinaryTree.levelOrderPrint(treeA);
-
 
32
        System.out.println();
26
        System.out.println( test_12_16());
33
        
27
 
34
        System.out.print("InOrder: "); BinaryTree.inOrderPrint(treeA);
28
        System.out.println(); //print a blank line
35
        System.out.println();
29
        test_traversals();
36
        
-
 
37
        
30
 
38
    } //end main
31
    } //end main test method
39
 
32
 
40
    public static BinaryTree createTestTree() {
33
    public static BinaryTree createTestTree() {
41
        BinaryTree treeB = new BinaryTree("B");
34
        BinaryTree treeB = new BinaryTree("B");
42
        BinaryTree treeD = new BinaryTree("D");
35
        BinaryTree treeD = new BinaryTree("D");
43
        BinaryTree treeE = new BinaryTree("E");
36
        BinaryTree treeE = new BinaryTree("E");
Line 135... Line 128...
135
        BinaryTree treeA = createTestTree();
128
        BinaryTree treeA = createTestTree();
136
 
129
 
137
        if( treeA.isBalanced() == true ) { return "test_12_10: PASSED"; }
130
        if( treeA.isBalanced() == true ) { return "test_12_10: PASSED"; }
138
        return "test_12_10: *** FAILED ***";
131
        return "test_12_10: *** FAILED ***";
139
    }
132
    }
-
 
133
    
-
 
134
    public static String test_12_11() {
-
 
135
        BinaryTree treeA = createTestTree();
-
 
136
    
-
 
137
        if( treeA.pathLength() == 6 ) { return "test_12_11: PASSED"; }
-
 
138
        return "test_12_11: *** FAILED *** val:" + treeA.pathLength();
-
 
139
    }
-
 
140
    
-
 
141
    public static String test_12_12() {
-
 
142
        BinaryTree treeA = createTestTree();
-
 
143
        
-
 
144
        String correctAnswer = "(((E),C,(D)),A,(B))";
-
 
145
        
-
 
146
        if( treeA.reverse().toString().equals(correctAnswer) ) {
-
 
147
            return "test_12_12: PASSED";
-
 
148
        }
140
 
149
 
141
    //public static String test_12_11() {
-
 
142
    //    BinaryTree treeA = createTestTree();
150
        return "test_12_12: *** FAILED *** " + treeA.reverse();
143
    //
151
    }
-
 
152
    
144
    //    if( treeA.pathLength() == 6 ) { return "test_12_11: PASSED"; }
153
    public static String test_12_13() {
145
    //    return "test_12_11: *** FAILED *** val:" + treeA.pathLength();
154
        BinaryTree treeA = createTestTree();
146
    //}
-
 
147
 
155
 
-
 
156
        if( treeA.level("E") == 2 ) { return "test_12_13: PASSED"; }
-
 
157
        return "test_12_13: *** FAILED ***";
-
 
158
    }
-
 
159
    
148
} //end class Driver
160
    public static String test_12_14() {
-
 
161
        BinaryTree treeA = createTestTree();
-
 
162
        BinaryTree treeB = new BinaryTree("B");
-
 
163
        
-
 
164
        if( treeA.isDisjointFrom(treeB) ) {
-
 
165
            return "test_12_14: *** FAILED ***";
-
 
166
        }
149
 
167
 
150
/*
-
 
151
      BufferedReader kb = new BufferedReader(
168
        return "test_12_14: PASSED";
152
                              new InputStreamReader(System.in));
-
 
-
 
169
    }
153
 
170
 
-
 
171
    public static String test_12_15() {
-
 
172
        BinaryTree treeA = createTestTree();
154
 
173
 
-
 
174
        if( treeA.isValid() ) { return "test_12_15: PASSED"; }
-
 
175
        return "test_12_15: *** FAILED ***";
-
 
176
    }
-
 
177
    
-
 
178
    public static String test_12_16() {
155
      BufferedReader br = new BufferedReader(
179
        BinaryTree tree1 = createTestTree();
156
                              new InputStreamReader(
180
        BinaryTree tree2 = createTestTree();
-
 
181
 
157
                                  new FileInputStream(filename)));
182
        if( tree1.equals(tree2) ) { return "test_12_16: PASSED"; }
-
 
183
        return "test_12_16: *** FAILED ***";
-
 
184
    }
-
 
185
    
-
 
186
    public static void test_traversals() {
-
 
187
        BinaryTree treeA = createTestTree();
-
 
188
        
-
 
189
        //print the correct answers
-
 
190
        System.out.println("Should Be:");
-
 
191
        System.out.println("PreOrder: A B C D E");
-
 
192
        System.out.println("PostOrder: B D E C A");
-
 
193
        System.out.println("LevelOrder: A B C D E");
-
 
194
        System.out.println("InOrder: B A D C E");
158
 
195
 
159
      PrintStream ps = new PrintStream(
196
        //print the actual answers
-
 
197
        System.out.println();
160
                           new FileOutputStream(
198
        System.out.println("Actually is:");
-
 
199
        System.out.print("PreOrder: "); BinaryTree.preOrderPrint(treeA); 
-
 
200
        System.out.println();
-
 
201
        System.out.print("PostOrder: "); BinaryTree.postOrderPrint(treeA);
-
 
202
        System.out.println();
-
 
203
        System.out.print("LevelOrder: "); BinaryTree.levelOrderPrint(treeA);
-
 
204
        System.out.println();
161
                               new File(filename)));
205
        System.out.print("InOrder: "); BinaryTree.inOrderPrint(treeA);
-
 
206
        System.out.println();
-
 
207
    }
162
 
208
 
163
*/
209
} //end class Driver
164
 
210