JavaAlgorithms
Elementary and no so elementary Java algorithms
treeAlgorithms/TestLCA.java
Go to the documentation of this file.
00001 
00009 package treeAlgorithms;
00010 
00011 import static org.junit.Assert.*;
00012 
00013 import org.junit.Test;
00014 
00020 public class TestLCA {
00021 
00022     @SuppressWarnings("javadoc")
00023     @Test
00024     public void test() {
00025         Integer numbers[] = new Integer[] { 20, 22, 8, 4, 12, 10, 14 };
00026         TreeBuilder<Integer> builder = new TreeBuilder<Integer>();
00027         for (Integer num : numbers) {
00028             builder.addNode(num);
00029         }
00030         TreeNode<Integer> root = builder.getTree();
00031         TestTree treeTest = new TestTree();
00032         assertTrue("LCA tree should be ordered", Algorithms.isOrdered(root));
00033         LeastCommonAncestor<Integer> lca = new LeastCommonAncestor<Integer>();
00034         TreeNode<Integer> lcaNode = lca.findLCA(root, 4, 14);
00035         int lcaValue = (Integer) lcaNode.getValue();
00036         assertTrue("LCA value should be 8, but is " + lcaValue, (lcaValue == 8));
00037     }
00038 
00039 }
 All Classes Namespaces Files Functions Variables