JAL-2759 Rationalising hidden cols cursor, and sorting out coverage
[jalview.git] / test / jalview / datamodel / HiddenColumnsCursorTest.java
index 3b1bc55..dc627bc 100644 (file)
@@ -30,6 +30,31 @@ import org.testng.annotations.Test;
 
 public class HiddenColumnsCursorTest
 {
+
+  @Test(groups = { "Functional" })
+  public void testConstructor()
+  {
+    HiddenColumnsCursor cursor = new HiddenColumnsCursor();
+    assertNull(cursor.findRegionForColumn(0, false));
+
+    List<int[]> hlist = new ArrayList<>();
+    cursor = new HiddenColumnsCursor(hlist);
+    assertNull(cursor.findRegionForColumn(0, false));
+
+    cursor = new HiddenColumnsCursor(hlist, 3, 12);
+    assertNull(cursor.findRegionForColumn(0, false));
+
+    hlist.add(new int[] { 3, 7 });
+    hlist.add(new int[] { 15, 25 });
+    cursor = new HiddenColumnsCursor(hlist);
+    HiddenCursorPosition p = cursor.findRegionForColumn(8, false);
+    assertEquals(1, p.getRegionIndex());
+
+    cursor = new HiddenColumnsCursor(hlist, 1, 5);
+    p = cursor.findRegionForColumn(8, false);
+    assertEquals(1, p.getRegionIndex());
+  }
+
   /**
    * Test the method which finds the corresponding region given a column
    */
@@ -92,7 +117,7 @@ public class HiddenColumnsCursorTest
    * Test the method which counts the number of hidden columns before a column
    */
   @Test(groups = { "Functional" })
-  public void testGetHiddenOffset()
+  public void testFindRegionForColumn_Visible()
   {
     HiddenColumnsCursor cursor = new HiddenColumnsCursor();
 
@@ -130,4 +155,30 @@ public class HiddenColumnsCursorTest
     assertEquals(46, offset);
   }
 
+  /**
+   * Test the method which updates for a deleted region
+   */
+  @Test(groups = { "Functional" })
+  public void testUpdateForDeletedRegion()
+  {
+    List<int[]> hlist = new ArrayList<>();
+    HiddenColumnsCursor cursor = new HiddenColumnsCursor(hlist, 1, 5);
+    cursor.updateForDeletedRegion(hlist, 0);
+    assertNull(cursor.findRegionForColumn(30, false));
+
+    hlist.add(new int[] { 3, 7 });
+    hlist.add(new int[] { 15, 25 });
+
+    cursor = new HiddenColumnsCursor(hlist, 1, 5);
+
+    HiddenCursorPosition p = cursor.findRegionForColumn(30, false);
+    assertEquals(16, p.getHiddenSoFar());
+
+    List<int[]> hlist2 = new ArrayList<>();
+    hlist2.add(new int[] { 3, 7 });
+    cursor.updateForDeletedRegion(hlist2, 11);
+    p = cursor.findRegionForColumn(30, false);
+    assertEquals(5, p.getHiddenSoFar());
+  }
+
 }