Added branch name tests
[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.gui.JvOptionPane;
7
8 import org.forester.archaeopteryx.MainFrame;
9 import org.forester.archaeopteryx.TreePanel;
10 import org.forester.phylogeny.Phylogeny;
11 import org.forester.phylogeny.PhylogenyNode;
12 import org.testng.annotations.BeforeClass;
13 import org.testng.annotations.Test;
14
15 public class AptxPhylogenyTreeTest extends TreeViewTest
16 {
17   final Phylogeny inputTree = new Phylogeny();
18
19   final PhylogenyNode rootNode = new PhylogenyNode("root");
20
21   final PhylogenyNode ancestor1Node = new PhylogenyNode("ancestor 1");
22
23   final PhylogenyNode ancestor2Node = new PhylogenyNode("leaf 2");
24
25   final PhylogenyNode leaf1aNode = new PhylogenyNode("leaf 1a");
26
27   final PhylogenyNode leaf1bNode = new PhylogenyNode("leaf 1b");
28
29   final PhylogenyNode leaf1cNode = new PhylogenyNode("leaf 1c");
30
31   Phylogeny tree;
32
33   TreePanel treePanel;
34
35   MainFrame aptx;
36
37
38   @Override
39   @BeforeClass(alwaysRun = true)
40   public void setUpTree()
41   {
42     ancestor1Node.addAsChild(leaf1aNode);
43     ancestor1Node.addAsChild(leaf1bNode);
44     ancestor1Node.addAsChild(leaf1cNode);
45
46     rootNode.addAsChild(ancestor1Node);
47     rootNode.addAsChild(ancestor2Node);
48
49     leaf1aNode.setDistanceToParent(2);
50     leaf1bNode.setDistanceToParent(3);
51     leaf1cNode.setDistanceToParent(4);
52
53     ancestor1Node.setDistanceToParent(36);
54     ancestor2Node.setDistanceToParent(42);
55
56     inputTree.setRoot(rootNode);
57     inputTree.setRooted(true);
58
59   }
60
61   @Override
62   @BeforeClass(dependsOnMethods = { "setUpJalview", "setUpTree" })
63   public void createTreeView()
64   {
65
66     treeView = ArchaeopteryxInit.createInstance(inputTree);
67     aptx = (MainFrame) treeView; // pretty ugly
68     treePanel = aptx.getMainPanel().getCurrentTreePanel();
69     tree = treePanel.getPhylogeny();
70   }
71
72
73   @BeforeClass(alwaysRun = true)
74   public void setUpJvOptionPane()
75   {
76     JvOptionPane.setInteractiveMode(false);
77     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
78   }
79
80   @Test(groups = "Functional")
81   public void testMainPanelExists()
82   {
83     assertTrue(aptx.getMainPanel() != null);
84   }
85
86   @Test(groups = "Functional")
87   public void testTreePanelExists()
88   {
89     assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
90   }
91
92   @Override
93   @Test(
94     groups = "Functional",
95     expectedExceptions = IllegalArgumentException.class)
96   public void testInvalidBranchName()
97   {
98     tree.getNode("I shouldn't exist");
99
100   }
101
102   @Override
103   @Test(groups = "Functional")
104   public void testExistingBranchName()
105   {
106     tree.getNode("leaf 2");
107
108   }
109
110   @Override
111   @Test(groups = "Functional")
112   public void testTreeLoaded()
113   {
114     assertTrue(aptx.getMainPanel().getCurrentTreePanel()
115             .getPhylogeny() != null);
116   }
117
118   @Override
119   @Test(groups = "Functional")
120   public void testChildNodesCount()
121   {
122     assertEquals(tree.getNode("ancestor 1").getNumberOfExternalNodes(), 3);
123
124   }
125
126   @Override
127   @Test(groups = "Functional")
128   public void testChildToParentBranchLength()
129   {
130     assertEquals(tree.getNode("leaf 1a").getDistanceToParent(), 2.0);
131
132   }
133
134   @Override
135   @Test(groups = "Functional")
136   public void testNodeToRootBranchLength()
137   {
138     assertEquals(tree.getNode("leaf 2").getDistanceToParent(), 42.0);
139
140   }
141
142   @Override
143   @Test(groups = "Functional")
144   public void testDistantNodeToRootBranchLength()
145   {
146     assertEquals(tree.getNode("leaf 1c").calculateDistanceToRoot(),
147             4.0 + 36.0);
148
149   }
150
151
152
153
154
155
156 }