Subversion Repositories programming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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() );
32 irasnyd 13
        System.out.println( test_12_6() );
14
        System.out.println( test_12_7() );
15
        System.out.println( test_12_8() );
33 irasnyd 16
        System.out.println( test_12_9() );
17
 
29 irasnyd 18
    } //end main
28 irasnyd 19
 
30 irasnyd 20
    public static BinaryTree createTestTree() {
29 irasnyd 21
        BinaryTree treeB = new BinaryTree("B");
22
        BinaryTree treeD = new BinaryTree("D");
23
        BinaryTree treeE = new BinaryTree("E");
24
        BinaryTree treeC = new BinaryTree("C",treeD,treeE);
25
        BinaryTree treeA = new BinaryTree("A",treeB,treeC);
26
 
30 irasnyd 27
        return treeA;
28
    }
29
 
30
    public static String test_12_2() {
31
        BinaryTree treeA = createTestTree();
32
 
29 irasnyd 33
        String experimentalResult = treeA.toString();
34
        String correctResult = "((B),A,((D),C,(E)))";
35
 
30 irasnyd 36
        if( correctResult.equals(experimentalResult) )
37
            return "test_12_2: PASSED";
38
 
39
        return "test_12_2: *** FAILED ***";
29 irasnyd 40
    }
31 irasnyd 41
 
42
    public static String test_12_3() {
43
        BinaryTree treeA = createTestTree();
44
        BinaryTree treeAleft = treeA.getLeft();
29 irasnyd 45
 
31 irasnyd 46
        if( treeA.isLeaf() == false && treeAleft.isLeaf() == true )
47
            return "test_12_3: PASSED";
29 irasnyd 48
 
31 irasnyd 49
        return "test_12_3: *** FAILED ***";
50
    }
51
 
52
    public static String test_12_4() {
53
        BinaryTree treeA = createTestTree();
54
        int correctResult = 5;
55
        int experimentalResult = treeA.size();
56
 
57
        if( correctResult == experimentalResult )
58
            return "test_12_4: PASSED";
59
 
60
        return "test_12_4: *** FAILED ***";
61
    }
62
 
63
    public static String test_12_5() {
64
        BinaryTree treeA = createTestTree();
65
        int correctResult = 2;
66
        int experimentalResult = treeA.height();
67
 
68
        if( correctResult == experimentalResult )
69
            return "test_12_5: PASSED";
70
 
71
        return "test_12_5: *** FAILED ***";
72
    }
73
 
32 irasnyd 74
    public static String test_12_6() {
75
        BinaryTree treeA = createTestTree();
76
 
77
        if( treeA.contains("B") &&
78
            treeA.contains("A") &&
79
            treeA.contains("D") &&
80
           !treeA.contains("Z") ) return "test_12_6: PASSED";
81
 
82
        return "test_12_6: *** FAILED ***";
83
    }
84
 
85
    public static String test_12_7() {
86
        BinaryTree treeA = createTestTree();
87
        int correctResult = 3;
88
 
89
        if( correctResult == treeA.numLeaves() )
90
            return "test_12_7: PASSED";
91
 
92
        return "test_12_7: *** FAILED ***";
93
    }
94
 
95
    public static String test_12_8() {
96
        BinaryTree treeA = createTestTree();
97
        BinaryTree tree = new BinaryTree("E",treeA,new BinaryTree("E"));
98
 
99
        int correctResult = 3;
100
 
101
        if( correctResult == tree.count("E") )
102
            return "test_12_8: PASSED";
103
 
104
        return "test_12_8: *** FAILED ***";
105
    }
106
 
33 irasnyd 107
    public static String test_12_9() {
108
        BinaryTree treeA = createTestTree();
109
 
110
        if( treeA.isFull() == false ) { return "test_12_9: PASSED"; }
111
        return "test_12_9: *** FAILED ***";
112
    }
113
 
28 irasnyd 114
} //end class Driver
115
 
116
/*
117
      BufferedReader kb = new BufferedReader(
118
                              new InputStreamReader(System.in));
119
 
120
 
121
      BufferedReader br = new BufferedReader(
122
                              new InputStreamReader(
123
                                  new FileInputStream(filename)));
124
 
125
      PrintStream ps = new PrintStream(
126
                           new FileOutputStream(
127
                               new File(filename)));
128
 
129
*/
130