Tests for Aptx tree created from a Phylogeny object added
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 24 Oct 2017 14:40:48 +0000 (15:40 +0100)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 24 Oct 2017 14:40:48 +0000 (15:40 +0100)
src/jalview/ext/archaeopteryx/ArchaeopteryxTreeBuilder.java
test/jalview/ext/archaeopteryx/AptxJalviewTreeTest.java [new file with mode: 0644]
test/jalview/ext/archaeopteryx/AptxPhylogenyTreeTest.java [moved from test/jalview/ext/archaeopteryx/AptxTreeCreationTest.java with 51% similarity]

index 1517ed3..7096eff 100644 (file)
@@ -58,6 +58,7 @@ public class ArchaeopteryxTreeBuilder // cannot inherit
 
   }
 
+  // testing method to be removed
   public Phylogeny buildAptxTree(SequenceI[] sequences)
   {
 
diff --git a/test/jalview/ext/archaeopteryx/AptxJalviewTreeTest.java b/test/jalview/ext/archaeopteryx/AptxJalviewTreeTest.java
new file mode 100644 (file)
index 0000000..a5beee2
--- /dev/null
@@ -0,0 +1,39 @@
+package jalview.ext.archaeopteryx;
+
+import jalview.analysis.TreeBuilder;
+import jalview.bin.Jalview;
+
+import org.forester.archaeopteryx.MainFrame;
+import org.forester.archaeopteryx.TreePanel;
+import org.forester.phylogeny.Phylogeny;
+import org.testng.annotations.BeforeClass;
+
+public class AptxJalviewTreeTest
+{
+  TreeBuilder jalviewTree;
+
+  TreePanel treePanel;
+
+  Phylogeny tree;
+
+  MainFrame aptx;
+
+  Jalview jalview;
+  
+  @BeforeClass(alwaysRun = true)
+  public void setUpTree()
+  {
+
+  }
+
+  @BeforeClass(dependsOnMethods = { "setUpTree" })
+  public void setUpJalview()
+  {
+    String[] args = new String[0];
+    Jalview.main(args);
+    aptx = ArchaeopteryxInit.createInstance(jalviewTree);
+
+    treePanel = aptx.getMainPanel().getCurrentTreePanel();
+    tree = treePanel.getPhylogeny();
+  }
+}
@@ -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);
+
+  }
+
+