JAL-2388 New hidden cols/seqs functions to support overview panel
[jalview.git] / test / jalview / datamodel / ColumnSelectionTest.java
index 5a915ce..49f29d7 100644 (file)
@@ -140,6 +140,65 @@ public class ColumnSelectionTest
   }
 
   /**
+   * Test the method that finds the visible column position a given distance
+   * before another column
+   */
+  @Test(groups = { "Functional" })
+  public void testFindColumnNToLeft()
+  {
+    ColumnSelection cs = new ColumnSelection();
+
+    // test that without hidden columns, findColumnNToLeft returns
+    // position n to left of provided position
+    int pos = cs.findColumnNToLeft(3, 10);
+    assertEquals(7, pos);
+
+    // 0 returns same position
+    pos = cs.findColumnNToLeft(0, 10);
+    assertEquals(10, pos);
+
+    // overflow to left returns negative number
+    pos = cs.findColumnNToLeft(3, 0);
+    assertEquals(-3, pos);
+
+    // test that with hidden columns to left of result column
+    // behaviour is the same as above
+    cs.hideColumns(1, 3);
+
+    // position n to left of provided position
+    pos = cs.findColumnNToLeft(3, 10);
+    assertEquals(7, pos);
+
+    // 0 returns same position
+    pos = cs.findColumnNToLeft(0, 10);
+    assertEquals(10, pos);
+
+    // test with one set of hidden columns between start and required position
+    cs.hideColumns(12, 15);
+    pos = cs.findColumnNToLeft(8, 17);
+    assertEquals(5, pos);
+
+    // test with two sets of hidden columns between start and required position
+    cs.hideColumns(20, 21);
+    pos = cs.findColumnNToLeft(8, 23);
+    assertEquals(9, pos);
+
+    // repeat last 2 tests with no hidden columns to left of required position
+    cs.revealAllHiddenColumns();
+
+    // test with one set of hidden columns between start and required position
+    cs.hideColumns(12, 15);
+    pos = cs.findColumnNToLeft(8, 17);
+    assertEquals(5, pos);
+
+    // test with two sets of hidden columns between start and required position
+    cs.hideColumns(20, 21);
+    pos = cs.findColumnNToLeft(8, 23);
+    assertEquals(9, pos);
+
+  }
+
+  /**
    * Test the code used to locate the reference sequence ruler origin
    */
   @Test(groups = { "Functional" })