JAL-3093 unit tests for finding annotation row index for mouse pos
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 1 Oct 2018 14:05:28 +0000 (15:05 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 1 Oct 2018 14:05:28 +0000 (15:05 +0100)
test/jalview/gui/AnnotationPanelTest.java [new file with mode: 0644]

diff --git a/test/jalview/gui/AnnotationPanelTest.java b/test/jalview/gui/AnnotationPanelTest.java
new file mode 100644 (file)
index 0000000..5f7d5a7
--- /dev/null
@@ -0,0 +1,51 @@
+package jalview.gui;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.datamodel.AlignmentAnnotation;
+
+import org.testng.annotations.Test;
+
+public class AnnotationPanelTest
+{
+
+  @Test(groups = "Functional")
+  public void testGetRowIndex()
+  {
+    assertEquals(AnnotationPanel.getRowIndex(0, null), -1);
+
+    AlignmentAnnotation[] anns = new AlignmentAnnotation[] {};
+    assertEquals(AnnotationPanel.getRowIndex(0, anns), -1);
+
+    AlignmentAnnotation ann1 = new AlignmentAnnotation(null, null, null);
+    AlignmentAnnotation ann2 = new AlignmentAnnotation(null, null, null);
+    AlignmentAnnotation ann3 = new AlignmentAnnotation(null, null, null);
+    ann1.visible = true;
+    ann2.visible = true;
+    ann3.visible = true;
+    ann1.height = 10;
+    ann2.height = 20;
+    ann3.height = 30;
+    anns = new AlignmentAnnotation[] { ann1, ann2, ann3 };
+
+    assertEquals(AnnotationPanel.getRowIndex(0, anns), 0);
+    assertEquals(AnnotationPanel.getRowIndex(9, anns), 0);
+    assertEquals(AnnotationPanel.getRowIndex(10, anns), 1);
+    assertEquals(AnnotationPanel.getRowIndex(29, anns), 1);
+    assertEquals(AnnotationPanel.getRowIndex(30, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(59, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(60, anns), -1);
+
+    ann2.visible = false;
+    assertEquals(AnnotationPanel.getRowIndex(0, anns), 0);
+    assertEquals(AnnotationPanel.getRowIndex(9, anns), 0);
+    assertEquals(AnnotationPanel.getRowIndex(10, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(39, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(40, anns), -1);
+
+    ann1.visible = false;
+    assertEquals(AnnotationPanel.getRowIndex(0, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(29, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(30, anns), -1);
+  }
+}