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