C:\Users\notebook\Documents\NetBeansProjects\CS2\src\testers\ColorBinaryTreeTester.java
  1 /*
  2  * This program is like BinaryTreeTester.java, but it adds color names
  3  * instead of animal names,
  4  */
  5 package testers;
  6 
  7 import trees.BinaryTree;
  8 import trees.BinaryTreeCreationException;
  9 
 10 /**
 11  * Tester for the BinaryTree data type
 12  *
 13  * @author notebook
 14  */
 15 public class ColorBinaryTreeTester {
 16 
 17     /**
 18      * @param args the command line arguments
 19      */
 20     public static void main(String[] args) throws BinaryTreeCreationException {
 21         testLR(); // test deterministic insertion +
 22         testST(); // test bst insertion +
 23         testND(); // test nondeterministic insertion +
 24         testND(); // test nondeterministic insertion +
 25     }
 26 
 27     private static void testLR() {
 28         System.out.println("Test LR ...");
 29         BinaryTree<String, String> t = new BinaryTree<String, String>();
 30         System.out.println(">> Creating empty tree.");
 31         System.out.println(">>> Adding elements to the tree directionally ...");
 32         try {
 33             t.addLR("red", null, "");
 34             t.addLR("blue", null, "l");
 35             t.addLR("green", null, "lr");
 36             t.addLR("black", null, "ll");
 37             t.addLR("white", null, "r");
 38             t.addLR("purple", null, "lrr");
 39             t.addLR("yellow", null, "rr");
 40             t.addLR("orange", null, "lrrl");
 41             t.addLR("indigo", null, "lrrll");
 42             t.addLR("aqua", null, "lll");
 43             t.addLR("tangerine", null, "rl");
 44             t.addLR("pink", null, "lrrlr");
 45             t.addLR("ghostwhite", null, "lrl");
 46             t.addLR("gray", null, "lrlr");
 47             t.addLR("brown", null, "lrll");
 48             t.addLR("gainsboro", null, "lrllr");
 49         } catch (BinaryTreeCreationException ex) {
 50             ex.printStackTrace();
 51         }
 52         System.out.println(">>> PREORDER");
 53         t.preorder();
 54         System.out.println(">>> INORDER");
 55         t.inorder();
 56         System.out.println(">>> POSTORDER");
 57         t.postorder();
 58         System.out.println(">>> HEIGHT = " + t.height());
 59     }
 60 
 61     private static void testST() throws BinaryTreeCreationException {
 62         System.out.println("Test BST ...");
 63         BinaryTree<String, String> t = new BinaryTree<String, String>();
 64         System.out.println(">> Creating empty tree.");
 65         System.out.println(">>> Adding elements to the binary search tree ...");
 66         t.addST("red", null);
 67         t.addST("blue", null);
 68         t.addST("green", null);
 69         t.addST("black", null);
 70         t.addST("white", null);
 71         t.addST("purple", null);
 72         t.addST("yellow", null);
 73         t.addST("orange", null);
 74         t.addST("indigo", null);
 75         t.addST("aqua", null);
 76         t.addST("tangerine", null);
 77         t.addST("pink", null);
 78         t.addST("ghostwhite", null);
 79         t.addST("gray", null);
 80         t.addST("brown", null);
 81         t.addST("gainsboro", null);
 82         System.out.println(">>> PREORDER");
 83         t.preorder();
 84         System.out.println(">>> INORDER");
 85         t.inorder();
 86         System.out.println(">>> POSTORDER");
 87         t.postorder();
 88         System.out.println(">>> HEIGHT = " + t.height());
 89     }
 90 
 91     private static void testND() {
 92         System.out.println("Test ND ...");
 93         BinaryTree<String, String> t = new BinaryTree<String, String>();
 94         System.out.println(">> Creating empty tree.");
 95         System.out.println(">>> Adding elements to the tree nondeterministically ...");
 96         t.addND("red", null);
 97         t.addND("blue", null);
 98         t.addND("green", null);
 99         t.addND("black", null);
100         t.addND("white", null);
101         t.addND("purple", null);
102         t.addND("yellow", null);
103         t.addND("orange", null);
104         t.addND("indigo", null);
105         t.addND("aqua", null);
106         t.addND("tangerine", null);
107         t.addND("pink", null);
108         t.addND("ghostwhite", null);
109         t.addND("gray", null);
110         t.addND("brown", null);
111         t.addND("gainsboro", null);
112         System.out.println(">>> PREORDER");
113         t.preorder();
114         System.out.println(">>> INORDER");
115         t.inorder();
116         System.out.println(">>> POSTORDER");
117         t.postorder();
118         System.out.println(">>> HEIGHT = " + t.height());
119     }
120 
121 }
122