import java.util.Arrays; /** * Runs a number of simple tests. * * @author Marcus */ public class Main { /** * Runs some tests. * * @param args Ignored. */ public static void main(String[] args) { // test stack System.out.println("Creating empty stack."); Stack stack = new Stack(); String[] test = new String[] { "A", "B", "C" }; for (int i = 0; i < test.length; i++) { System.out.println("Size is " + stack.size() + " should be " + i); System.out.println("Adding " + test[i]); stack.addToTop(test[i]); } for (int i = 0; i < test.length; i++) { System.out.println("Size is " + stack.size() + " should be " + (test.length - i)); System.out.println("Removing element."); String last = stack.removeFromTop(); System.out.println("Result should be " + test[test.length - 1 - i] + " and was " + last); } System.out.println(); // test tree System.out.println("Creating tree with 4 nodes: 2, 1, 3, 1"); Tree tree = new Tree(); tree.insert(2); tree.insert(1); tree.insert(3); tree.insert(1); System.out.println("Node count of 2 should be 1 and was " + tree.count(2)); System.out.println("Node count of 1 should be 2 and was " + tree.count(1)); System.out.println("Visiting all nodes in post-order."); TreeVisitor v = new TreeVisitor(); tree.traverse(v); System.out.println("Sequence should be [3.0, 1.0, 1.0, 2.0] and was " + Arrays.toString(v.toArray())); } }