Tests for Aptx tree created from a Phylogeny object added
[jalview.git] / test / jalview / ext / archaeopteryx / AptxPhylogenyTreeTest.java
@@ -1,5 +1,6 @@
 package jalview.ext.archaeopteryx;
 
+import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
 import jalview.bin.Jalview;
@@ -13,15 +14,15 @@ import org.forester.phylogeny.PhylogenyNode;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-public class AptxTreeCreationTest
+public class AptxPhylogenyTreeTest
 {
-  final Phylogeny phy = new Phylogeny();
+  final Phylogeny inputTree = new Phylogeny();
 
   final PhylogenyNode rootNode = new PhylogenyNode("root");
 
   final PhylogenyNode ancestor1Node = new PhylogenyNode("ancestor 1");
 
-  final PhylogenyNode leaf2Node = new PhylogenyNode("leaf 2");
+  final PhylogenyNode ancestor2Node = new PhylogenyNode("ancestor 2");
 
   final PhylogenyNode leaf1aNode = new PhylogenyNode("leaf 1a");
 
@@ -29,42 +30,48 @@ public class AptxTreeCreationTest
 
   final PhylogenyNode leaf1cNode = new PhylogenyNode("leaf 1c");
 
-  MainFrame aptx;
-
   TreePanel treePanel;
 
+  Phylogeny tree;
+
+  MainFrame aptx;
+
   Jalview jalview;
 
   @BeforeClass(alwaysRun = true)
-  public void setUpTrees()
+  public void setUpTree()
   {
     ancestor1Node.addAsChild(leaf1aNode);
     ancestor1Node.addAsChild(leaf1bNode);
     ancestor1Node.addAsChild(leaf1cNode);
 
     rootNode.addAsChild(ancestor1Node);
-    rootNode.addAsChild(leaf2Node);
+    rootNode.addAsChild(ancestor2Node);
 
     leaf1aNode.setDistanceToParent(2);
     leaf1bNode.setDistanceToParent(3);
     leaf1cNode.setDistanceToParent(4);
 
     ancestor1Node.setDistanceToParent(36);
-    leaf2Node.setDistanceToParent(42);
+    ancestor2Node.setDistanceToParent(42);
 
-    phy.setRoot(rootNode);
-    phy.setRooted(true);
+    inputTree.setRoot(rootNode);
+    inputTree.setRooted(true);
 
   }
 
-  @BeforeClass(alwaysRun = true)
+  @BeforeClass(dependsOnMethods = { "setUpTree" })
   public void setUpJalview()
   {
     String[] args = new String[0];
     Jalview.main(args);
-    aptx = ArchaeopteryxInit.createInstance(phy);
+    aptx = ArchaeopteryxInit.createInstance(inputTree);
+
+    treePanel = aptx.getMainPanel().getCurrentTreePanel();
+    tree = treePanel.getPhylogeny();
   }
 
+
   @BeforeClass(alwaysRun = true)
   public void setUpJvOptionPane()
   {
@@ -78,6 +85,7 @@ public class AptxTreeCreationTest
     assertTrue(aptx != null);
   }
 
+
   @Test(groups = "Functional")
   public void testAptxBoundToJalview()
   {
@@ -85,27 +93,60 @@ public class AptxTreeCreationTest
   }
 
   @Test(groups = "Functional")
-  public void testShowingTree()
+  public void testShowingAptx()
   {
     assertTrue(aptx.isShowing());
 
   }
 
-  // @Test(groups = "Functional")
-  // public void testCorrectBranchLengths()
-  //
-  // {
-  // aptx.getMainPanel().getTabbedPane().setSelectedIndex(0); // select the
-  // // first
-  // // (and only) tree
-  // // panel
-  // treePanel = aptx.getMainPanel().getCurrentTreePanel();
-  //
-  // System.out.println(treePanel);
-  //
-  //
-  //
-  // }
+  @Test(groups = "Functional")
+  public void testMainPanelExists()
+  {
+    assertTrue(aptx.getMainPanel() != null);
+  }
+
+  @Test(groups = "Functional")
+  public void testTreePanelExists()
+  {
+    assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
+  }
+
+  @Test(groups = "Functional")
+  public void testTreeLoaded()
+  {
+    assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
+  }
+
+  @Test(groups = "Functional")
+  public void testChildNodesCount()
+  {
+    assertEquals(tree.getNode("ancestor 1").getNumberOfExternalNodes(), 3);
+
+  }
+
+  @Test(groups = "Functional")
+  public void testCorrectLeafToParentBranchLength()
+  {
+    assertEquals(tree.getNode("leaf 1a").getDistanceToParent(), 2.0);
+
+  }
+
+  @Test(groups = "Functional")
+  public void testCorrectAncestorLeafToRootBranchLength()
+  {
+    assertEquals(tree.getNode("ancestor 2").getDistanceToParent(), 42.0);
+
+  }
+
+  @Test(groups = "Functional")
+  public void testCorrectLeafToRootBranchLength()
+  {
+    assertEquals(tree.getNode("leaf 1c").calculateDistanceToRoot(),
+            4.0 + 36.0);
+
+  }
+
+