public static void main(String[] args) { SplayTree myNameIsSonyAndICantProgram = new SplayTree(); // We won't be using this, I just felt it was necessary. SplayTree splay = new SplayTree(); // Randomly creates a SplayTree, printing out the Tree after each insert int rand = (int) (Math.random() * 25 + .5); for (int i = 0; i < rand; i++) { int temp = (int) (Math.random() * 100 + .5); System.out.println("Attempting to add " + temp + " to the SplayTree:\nNew SplayTree:"); splay.insert(temp); print(splay.getRoot()); } // Removes all of the data by the root while (splay.getSize() > 0) { if (splay.getRoot() != null) { System.out.println( "Attempting to remove " + splay.getRoot().getValue() + " from the tree.\nNew SplayTree:"); splay.remove(splay.getRoot().getValue()); print(splay.getRoot()); } else break; } }
@Test public void testIsLeftChild() { assertFalse(SplayTree.isLeftChild(tree.getRoot())); assertFalse(SplayTree.isLeftChild(tree.getRoot().right)); assertFalse(SplayTree.isLeftChild(tree.getRoot().left)); SplayTree.Node root = tree.getRoot(); SplayTree.Node node = tree.new Node(); root.left = node; node.parent = root; assertTrue(SplayTree.isLeftChild(node)); }
@Test public void testConstructor() { SplayTree.Node root = tree.getRoot(); int nodes = 0; SplayTree.Node maxNode = root; while (maxNode != null) { if (maxNode != root) { assertEquals(maxNode.val, maxNode.parent.val + 1); } else { assertEquals(0, maxNode.val); } nodes++; maxNode = maxNode.right; } assertEquals(4, nodes); }
@Override public Word get(Word word) { // TODO Auto-generated method stub return (Word) splayTree.find(word); }
public void add(Word wordObject) { splayTree.insert(wordObject); }