From: gmungoc Date: Thu, 19 Jan 2017 10:29:04 +0000 (+0000) Subject: JAL-2370 unit tests for extracted ColumnSelection.stretchGroup() X-Git-Tag: Release_2_10_3b1~368 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f976c25c5ad6539698c8fac322362adcc014649d;p=jalview.git JAL-2370 unit tests for extracted ColumnSelection.stretchGroup() --- diff --git a/test/jalview/datamodel/ColumnSelectionTest.java b/test/jalview/datamodel/ColumnSelectionTest.java index 4faa482..1d819c9 100644 --- a/test/jalview/datamodel/ColumnSelectionTest.java +++ b/test/jalview/datamodel/ColumnSelectionTest.java @@ -815,4 +815,67 @@ public class ColumnSelectionTest assertEquals("[10, 50]", Arrays.toString(hidden.get(0))); assertEquals("[60, 70]", Arrays.toString(hidden.get(1))); } + + @Test(groups = { "Functional" }) + public void testStretchGroup_expand() + { + /* + * test that emulates clicking column 4 (selected) + * and dragging right to column 5 (all base 0) + */ + ColumnSelection cs = new ColumnSelection(); + cs.addElement(4); + SequenceGroup sg = new SequenceGroup(); + sg.setStartRes(4); + sg.setEndRes(4); + cs.stretchGroup(5, sg, 4, 4); + assertEquals(cs.getSelected().size(), 2); + assertTrue(cs.contains(4)); + assertTrue(cs.contains(5)); + assertEquals(sg.getStartRes(), 4); + assertEquals(sg.getEndRes(), 5); + + /* + * emulate drag right with columns 10-20 already selected + */ + cs.clear(); + for (int i = 10; i <= 20; i++) + { + cs.addElement(i); + } + assertEquals(cs.getSelected().size(), 11); + sg = new SequenceGroup(); + sg.setStartRes(10); + sg.setEndRes(20); + cs.stretchGroup(21, sg, 10, 20); + assertEquals(cs.getSelected().size(), 12); + assertTrue(cs.contains(10)); + assertTrue(cs.contains(21)); + assertEquals(sg.getStartRes(), 10); + assertEquals(sg.getEndRes(), 21); + } + + @Test(groups = { "Functional" }) + public void testStretchGroup_shrink() + { + /* + * emulate drag left to 19 with columns 10-20 already selected + */ + ColumnSelection cs = new ColumnSelection(); + for (int i = 10; i <= 20; i++) + { + cs.addElement(i); + } + assertEquals(cs.getSelected().size(), 11); + SequenceGroup sg = new SequenceGroup(); + sg.setStartRes(10); + sg.setEndRes(20); + cs.stretchGroup(19, sg, 10, 20); + assertEquals(cs.getSelected().size(), 10); + assertTrue(cs.contains(10)); + assertTrue(cs.contains(19)); + assertFalse(cs.contains(20)); + assertEquals(sg.getStartRes(), 10); + assertEquals(sg.getEndRes(), 19); + } }