From: gmungoc Date: Tue, 16 Aug 2016 15:52:03 +0000 (+0100) Subject: JAL-2172 unit test added X-Git-Tag: Release_2_10_0~107 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9663a29dfe0402914e7b1e8f9b689a8b92a6d536;p=jalview.git JAL-2172 unit test added --- diff --git a/test/jalview/datamodel/ColumnSelectionTest.java b/test/jalview/datamodel/ColumnSelectionTest.java index 1a7ae32..04af3ce 100644 --- a/test/jalview/datamodel/ColumnSelectionTest.java +++ b/test/jalview/datamodel/ColumnSelectionTest.java @@ -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); @@ -527,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 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()); + } }