Files
2025-07-21 16:03:34 +02:00

48 lines
1.4 KiB
Java

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 list
System.out.println("Creating empty list.");
List list = new List();
String[] test = new String[] { "A", "B", "C" };
for (int i = 0; i < test.length; i++) {
System.out.println("Size is " + list.size() + " should be " + i);
System.out.println("Adding " + test[i]);
list.addLast(test[i]);
}
for (int i = 0; i < test.length; i++) {
System.out.println("Size is " + list.size() + " should be " + (test.length - i));
System.out.println("Removing last element.");
String last = list.removeLast();
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 pre-order.");
TreeVisitor v = new TreeVisitor();
tree.traverse(v);
System.out.println("Sequence should be [2.0, 1.0, 1.0, 3.0] and was " + Arrays.toString(v.toArray()));
}
}