From: kiramt Date: Tue, 3 Oct 2017 15:23:40 +0000 (+0100) Subject: JAL-2647 unit test X-Git-Tag: Release_2_10_4~55^2~1^2~89 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8aefc03883faf95c47dd0d6359bfba8147e3714e;p=jalview.git JAL-2647 unit test --- diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 192a822..6f1260c 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -1416,4 +1416,133 @@ public class HiddenColumnsTest assertEquals(6, next); assertFalse(it.hasNext()); } + + @Test(groups = "Functional") + public void testVisibleBlocksVisBoundsIterator() + { + HiddenColumns h = new HiddenColumns(); + Iterator regions = h.getVisibleBlocksIterator(0, 30, true); + + // only 1 visible region spanning 0-30 if nothing is hidden + assertTrue(regions.hasNext()); + int[] region = regions.next(); + assertEquals(0, region[0]); + assertEquals(30, region[1]); + assertFalse(regions.hasNext()); + + // hide 1 region in middle + // 2 regions one on either side + // second region boundary accounts for hidden columns + h.hideColumns(10, 15); + regions = h.getVisibleBlocksIterator(0, 30, true); + + assertTrue(regions.hasNext()); + region = regions.next(); + assertEquals(0, region[0]); + assertEquals(9, region[1]); + region = regions.next(); + assertEquals(16, region[0]); + assertEquals(36, region[1]); + assertFalse(regions.hasNext()); + + // single hidden region at left + h = new HiddenColumns(); + h.hideColumns(0, 5); + regions = h.getVisibleBlocksIterator(0, 30, true); + + assertTrue(regions.hasNext()); + region = regions.next(); + assertEquals(6, region[0]); + assertEquals(36, region[1]); + assertFalse(regions.hasNext()); + + // single hidden region at right + h = new HiddenColumns(); + h.hideColumns(27, 30); + regions = h.getVisibleBlocksIterator(0, 30, true); + + assertTrue(regions.hasNext()); + region = regions.next(); + assertEquals(0, region[0]); + assertEquals(26, region[1]); + region = regions.next(); + assertEquals(31, region[0]); + assertEquals(34, region[1]); + assertFalse(regions.hasNext()); + + // hidden region at left + hidden region in middle + h = new HiddenColumns(); + h.hideColumns(0, 5); + h.hideColumns(23, 25); + regions = h.getVisibleBlocksIterator(0, 30, true); + + assertTrue(regions.hasNext()); + region = regions.next(); + assertEquals(6, region[0]); + assertEquals(22, region[1]); + region = regions.next(); + assertEquals(26, region[0]); + assertEquals(39, region[1]); + assertFalse(regions.hasNext()); + + // hidden region at right + hidden region in middle + h = new HiddenColumns(); + h.hideColumns(27, 30); + h.hideColumns(11, 14); + regions = h.getVisibleBlocksIterator(0, 30, true); + + assertTrue(regions.hasNext()); + region = regions.next(); + assertEquals(0, region[0]); + assertEquals(10, region[1]); + region = regions.next(); + assertEquals(15, region[0]); + assertEquals(26, region[1]); + region = regions.next(); + assertEquals(31, region[0]); + assertEquals(38, region[1]); + assertFalse(regions.hasNext()); + + // hidden region at left and right + h = new HiddenColumns(); + h.hideColumns(27, 35); + h.hideColumns(0, 4); + regions = h.getVisibleBlocksIterator(0, 30, true); + + assertTrue(regions.hasNext()); + region = regions.next(); + assertEquals(5, region[0]); + assertEquals(26, region[1]); + region = regions.next(); + assertEquals(36, region[0]); + assertEquals(44, region[1]); + assertFalse(regions.hasNext()); + + // multiple hidden regions + h = new HiddenColumns(); + h.hideColumns(1, 1); + h.hideColumns(3, 5); + h.hideColumns(9, 11); + h.hideColumns(22, 26); + + regions = h.getVisibleBlocksIterator(0, 30, true); + + assertTrue(regions.hasNext()); + region = regions.next(); + assertEquals(0, region[0]); + assertEquals(0, region[1]); + region = regions.next(); + assertEquals(2, region[0]); + assertEquals(2, region[1]); + region = regions.next(); + assertEquals(6, region[0]); + assertEquals(8, region[1]); + region = regions.next(); + assertEquals(12, region[0]); + assertEquals(21, region[1]); + region = regions.next(); + assertEquals(27, region[0]); + assertEquals(42, region[1]); + assertFalse(regions.hasNext()); + } }