Merge branch 'develop' into bug/JAL-1841rnaSecStr
[jalview.git] / test / jalview / datamodel / ColumnSelectionTest.java
index e1d04eb..04af3ce 100644 (file)
@@ -325,10 +325,14 @@ public class ColumnSelectionTest
    * this fails, HideSelectedColumns may also fail
    */
   @Test(groups = { "Functional" })
-  public void testgetSelectedRanges()
+  public void testGetSelectedRanges()
   {
+    /*
+     * getSelectedRanges returns ordered columns regardless
+     * of the order in which they are added
+     */
     ColumnSelection cs = new ColumnSelection();
-    int[] sel = { 2, 3, 4, 7, 8, 9, 20, 21, 22 };
+    int[] sel = { 4, 3, 7, 21, 9, 20, 8, 22, 2 };
     for (int col : sel)
     {
       cs.addElement(col);
@@ -495,6 +499,12 @@ public class ColumnSelectionTest
     cs2.addElement(1);
     cs2.addElement(513);
     cs2.addElement(0);
+
+    // with no hidden columns
+    assertFalse(cs.equals(cs2));
+    assertFalse(cs2.equals(cs));
+
+    // with hidden columns added in a different order
     cs2.hideColumns(6, 9);
     cs2.hideColumns(5, 8);
     cs2.hideColumns(3);
@@ -521,4 +531,35 @@ public class ColumnSelectionTest
     cs.addElement(88);
     assertTrue(cs.equals(cs2));
   }
+
+  /**
+   * Test the method that returns selected columns, in the order in which they
+   * were added
+   */
+  @Test(groups = { "Functional" })
+  public void testGetSelection()
+  {
+    ColumnSelection cs = new ColumnSelection();
+    int[] sel = { 4, 3, 7, 21 };
+    for (int col : sel)
+    {
+      cs.addElement(col);
+    }
+    List<Integer> selected = cs.getSelected();
+    assertEquals(4, selected.size());
+    int i = 0;
+    for (int col : sel)
+    {
+      assertEquals(col, selected.get(i++).intValue());
+    }
+
+    cs.removeElement(7);
+    cs.addElement(1);
+    cs.removeElement(4);
+    selected = cs.getSelected();
+    assertEquals(3, selected.size());
+    assertEquals(3, selected.get(0).intValue());
+    assertEquals(21, selected.get(1).intValue());
+    assertEquals(1, selected.get(2).intValue());
+  }
 }