1 22 package test.dbc; 23 24 import junit.framework.TestCase; 25 import test.dbc.java.Sorter; 26 import test.dbc.office.Computer; 27 import test.dbc.office.Developer; 28 import test.dbc.office.OfficeManager; 29 import test.dbc.stack.Stack; 30 import test.dbc.stack.StackImpl; 31 32 37 public class Driver 38 { 39 public void testOffice()throws Exception 40 { 41 System.out.println("****************** TEST OFFICE ******************"); 42 OfficeManager officeManager = new OfficeManager(); 43 44 Computer compA = officeManager.createComputer("comp A"); 45 Developer kabir = officeManager.createDeveloper("Kabir"); 46 47 officeManager.assignComputer(compA, kabir); 48 49 50 Developer bill = officeManager.createDeveloper("Bill"); 51 52 Computer compB = officeManager.createComputer("comp B"); 53 officeManager.assignComputer(compB, bill); 54 55 try 56 { 57 officeManager.createDeveloper(null); 58 if (true)throw new Exception ("Did not validate developer null name"); 59 } 60 catch(RuntimeException e) 61 { 62 } 63 64 } 65 66 public void testStack()throws Exception 67 { 68 System.out.println("****************** TEST STACK ******************"); 69 Stack s = new StackImpl(); 70 s.push("one"); 71 s.push("two"); 72 s.pop(); 73 74 s.push("two"); 75 s.push("three"); 76 s.pop(); 77 s.pop(); 78 s.pop(); 79 try 80 { 81 s.pop(); 82 throw new Exception ("Did not validate empty stack before pop"); 83 } 84 catch(RuntimeException e) 85 { 86 System.out.println(e.getMessage()); 87 } 88 } 89 90 public void testJavaExpression()throws Exception 91 { 92 System.out.println("****************** TEST SORTER ******************"); 93 94 int[] unsorted = new int[]{4, 1, 5, 3}; 95 int[] sorted = Sorter.sort(unsorted); 96 97 try 98 { 99 Sorter.brokenSort(unsorted); 100 throw new Exception ("Did not validate list was not sorted"); 101 } 102 catch(RuntimeException e) 103 { 104 System.out.println(e.getMessage()); 105 } 106 } 107 108 public static void main(String [] args) 109 { 110 try 111 { 112 Driver d = new Driver(); 113 d.testOffice(); 114 d.testStack(); 115 d.testJavaExpression(); 116 } 117 catch(Exception e) 118 { 119 System.out.println("Error: " + e.getMessage()); 120 e.printStackTrace(); 121 } 122 } 123 } | Popular Tags |