Tests for Aptx tree created from a Phylogeny object added
[jalview.git] / test / jalview / ext / archaeopteryx / AptxPhylogenyTreeTest.java
1 package jalview.ext.archaeopteryx;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertTrue;
5
6 import jalview.bin.Jalview;
7 import jalview.gui.Desktop;
8 import jalview.gui.JvOptionPane;
9
10 import org.forester.archaeopteryx.MainFrame;
11 import org.forester.archaeopteryx.TreePanel;
12 import org.forester.phylogeny.Phylogeny;
13 import org.forester.phylogeny.PhylogenyNode;
14 import org.testng.annotations.BeforeClass;
15 import org.testng.annotations.Test;
16
17 public class AptxPhylogenyTreeTest
18 {
19   final Phylogeny inputTree = new Phylogeny();
20
21   final PhylogenyNode rootNode = new PhylogenyNode("root");
22
23   final PhylogenyNode ancestor1Node = new PhylogenyNode("ancestor 1");
24
25   final PhylogenyNode ancestor2Node = new PhylogenyNode("ancestor 2");
26
27   final PhylogenyNode leaf1aNode = new PhylogenyNode("leaf 1a");
28
29   final PhylogenyNode leaf1bNode = new PhylogenyNode("leaf 1b");
30
31   final PhylogenyNode leaf1cNode = new PhylogenyNode("leaf 1c");
32
33   TreePanel treePanel;
34
35   Phylogeny tree;
36
37   MainFrame aptx;
38
39   Jalview jalview;
40
41   @BeforeClass(alwaysRun = true)
42   public void setUpTree()
43   {
44     ancestor1Node.addAsChild(leaf1aNode);
45     ancestor1Node.addAsChild(leaf1bNode);
46     ancestor1Node.addAsChild(leaf1cNode);
47
48     rootNode.addAsChild(ancestor1Node);
49     rootNode.addAsChild(ancestor2Node);
50
51     leaf1aNode.setDistanceToParent(2);
52     leaf1bNode.setDistanceToParent(3);
53     leaf1cNode.setDistanceToParent(4);
54
55     ancestor1Node.setDistanceToParent(36);
56     ancestor2Node.setDistanceToParent(42);
57
58     inputTree.setRoot(rootNode);
59     inputTree.setRooted(true);
60
61   }
62
63   @BeforeClass(dependsOnMethods = { "setUpTree" })
64   public void setUpJalview()
65   {
66     String[] args = new String[0];
67     Jalview.main(args);
68     aptx = ArchaeopteryxInit.createInstance(inputTree);
69
70     treePanel = aptx.getMainPanel().getCurrentTreePanel();
71     tree = treePanel.getPhylogeny();
72   }
73
74
75   @BeforeClass(alwaysRun = true)
76   public void setUpJvOptionPane()
77   {
78     JvOptionPane.setInteractiveMode(false);
79     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
80   }
81
82   @Test(groups = "Functional")
83   public void testAptxExists()
84   {
85     assertTrue(aptx != null);
86   }
87
88
89   @Test(groups = "Functional")
90   public void testAptxBoundToJalview()
91   {
92     assertTrue(aptx.getTopLevelAncestor() instanceof Desktop);
93   }
94
95   @Test(groups = "Functional")
96   public void testShowingAptx()
97   {
98     assertTrue(aptx.isShowing());
99
100   }
101
102   @Test(groups = "Functional")
103   public void testMainPanelExists()
104   {
105     assertTrue(aptx.getMainPanel() != null);
106   }
107
108   @Test(groups = "Functional")
109   public void testTreePanelExists()
110   {
111     assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
112   }
113
114   @Test(groups = "Functional")
115   public void testTreeLoaded()
116   {
117     assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
118   }
119
120   @Test(groups = "Functional")
121   public void testChildNodesCount()
122   {
123     assertEquals(tree.getNode("ancestor 1").getNumberOfExternalNodes(), 3);
124
125   }
126
127   @Test(groups = "Functional")
128   public void testCorrectLeafToParentBranchLength()
129   {
130     assertEquals(tree.getNode("leaf 1a").getDistanceToParent(), 2.0);
131
132   }
133
134   @Test(groups = "Functional")
135   public void testCorrectAncestorLeafToRootBranchLength()
136   {
137     assertEquals(tree.getNode("ancestor 2").getDistanceToParent(), 42.0);
138
139   }
140
141   @Test(groups = "Functional")
142   public void testCorrectLeafToRootBranchLength()
143   {
144     assertEquals(tree.getNode("leaf 1c").calculateDistanceToRoot(),
145             4.0 + 36.0);
146
147   }
148
149
150
151
152
153 }