C:\Users\notebook\Documents\NetBeansProjects\CS2\src\testers\BinaryTreeTester.java
  1 /*
  2  * BinaryTreeTester.java of testers package
  3  */
  4 package testers;
  5 
  6 import trees.BinaryTree;
  7 import trees.BinaryTreeCreationException;
  8 
  9 /**
 10  * Tester for the BinaryTree data type
 11  *
 12  * @author notebook
 13  */
 14 public class BinaryTreeTester {
 15 
 16     /**
 17      * @param args the command line arguments
 18      */
 19     public static void main(String[] args) throws BinaryTreeCreationException {
 20         testLR(); // test deterministic insertioni +
 21         testST(); // test bst insertion +
 22         testND(); // test nondeterministic insertion +
 23         testND(); // test nondeterministic insertion +
 24     }
 25 
 26     private static void testLR() {
 27         System.out.println("Test LR ...");
 28         BinaryTree<String, String> t = new BinaryTree<String, String>();
 29         System.out.println(">> Creating empty tree.");
 30         System.out.println(">>> Adding elements to the tree directionally ...");
 31         try {
 32             t.addLR("lion", null, "");
 33             t.addLR("shark", null, "r");
 34             t.addLR("elephant", null, "l");
 35             t.addLR("zebra", null, "rr");
 36             t.addLR("alligator", null, "ll");
 37             t.addLR("ardvaark", null, "llr");
 38             t.addLR("tiger", null, "rrl");
 39             t.addLR("giraffe", null, "lr");
 40             t.addLR("bear", null, "llrr");
 41             t.addLR("snake", null, "rrll");
 42         } catch (BinaryTreeCreationException ex) {
 43             ex.printStackTrace();
 44         }
 45         System.out.println(">>> PREORDER");
 46         t.preorder();
 47         System.out.println(">>> INORDER");
 48         t.inorder();
 49         System.out.println(">>> POSTORDER");
 50         t.postorder();
 51         System.out.println(">>> HEIGHT = " + t.height());
 52     }
 53 
 54     private static void testST() throws BinaryTreeCreationException {
 55         System.out.println("Test BST ...");
 56         BinaryTree<String, String> t = new BinaryTree<String, String>();
 57         System.out.println(">> Creating empty tree.");
 58         System.out.println(">>> Adding elements to the binary search tree ...");
 59         t.addST("lion", null);
 60         t.addST("shark", null);
 61         t.addST("elephant", null);
 62         t.addST("zebra", null);
 63         t.addST("alligator", null);
 64         t.addST("ardvaark", null);
 65         t.addST("tiger", null);
 66         t.addST("giraffe", null);
 67         t.addST("bear", null);
 68         t.addST("snake", null);
 69         System.out.println(">>> PREORDER");
 70         t.preorder();
 71         System.out.println(">>> INORDER");
 72         t.inorder();
 73         System.out.println(">>> POSTORDER");
 74         t.postorder();
 75         System.out.println(">>> HEIGHT = " + t.height());
 76     }
 77 
 78     private static void testND() {
 79         System.out.println("Test ND ...");
 80         BinaryTree<String, String> t = new BinaryTree<String, String>();
 81         System.out.println(">> Creating empty tree.");
 82         System.out.println(">>> Adding elements to the tree nondeterministically ...");
 83         t.addND("lion", null);
 84         t.addND("shark", null);
 85         t.addND("elephant", null);
 86         t.addND("zebra", null);
 87         t.addND("alligator", null);
 88         t.addND("ardvaark", null);
 89         t.addND("tiger", null);
 90         t.addND("giraffe", null);
 91         t.addND("bear", null);
 92         t.addND("snake", null);
 93         System.out.println(">>> PREORDER");
 94         t.preorder();
 95         System.out.println(">>> INORDER");
 96         t.inorder();
 97         System.out.println(">>> POSTORDER");
 98         t.postorder();
 99         System.out.println(">>> HEIGHT = " + t.height());
100     }
101 
102 }
103