From: kiramt Date: Tue, 30 Jan 2018 10:56:15 +0000 (+0000) Subject: JAL-2759 Additional tests and tweaks to numColumns update X-Git-Tag: Release_2_10_4~55^2~1^2~14 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3998db6686fa26ecbc9536c84f64e8bf1059aa5f;p=jalview.git JAL-2759 Additional tests and tweaks to numColumns update --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index d2e46c6..dfa0890 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -287,7 +287,6 @@ public class HiddenColumns region[1] = Math.max(region[1], end); numColumns += oldstart - region[0]; - numColumns += region[1] - oldend; /* * also update or remove any subsequent ranges @@ -305,11 +304,10 @@ public class HiddenColumns break; } numColumns -= nextRegion[1] - nextRegion[0] + 1; - oldend = nextRegion[1]; region[1] = Math.max(nextRegion[1], end); - numColumns += region[1] - oldend + 1; endi++; } + numColumns += region[1] - oldend; hiddenColumns.subList(i + 1, endi + 1).clear(); } diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 45df6da..e4aa8e2 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -488,11 +488,13 @@ public class HiddenColumnsTest assertEquals(2, cs.getNumberOfRegions()); assertEquals("[49, 59]", Arrays.toString(regions.next())); assertEquals("[69, 79]", Arrays.toString(regions.next())); + assertEquals(22, cs.getSize()); cs.hideColumns(48, 80); regions = cs.iterator(); assertEquals(1, cs.getNumberOfRegions()); assertEquals("[48, 80]", Arrays.toString(regions.next())); + assertEquals(33, cs.getSize()); /* * another...joining hidden ranges @@ -506,6 +508,7 @@ public class HiddenColumnsTest regions = cs.iterator(); assertEquals(1, cs.getNumberOfRegions()); assertEquals("[10, 60]", Arrays.toString(regions.next())); + assertEquals(51, cs.getSize()); /* * another...left overlap, subsumption, right overlap, @@ -523,6 +526,7 @@ public class HiddenColumnsTest assertEquals(2, cs.getNumberOfRegions()); assertEquals("[10, 50]", Arrays.toString(regions.next())); assertEquals("[60, 70]", Arrays.toString(regions.next())); + assertEquals(52, cs.getSize()); } @Test(groups = { "Functional" }) @@ -537,22 +541,26 @@ public class HiddenColumnsTest cs = new HiddenColumns(); cs.hideColumns(one); assertEquals(1, cs.getNumberOfRegions()); + assertEquals(1, cs.getSize()); one.set(2); cs = new HiddenColumns(); cs.hideColumns(one); assertEquals(1, cs.getNumberOfRegions()); + assertEquals(2, cs.getSize()); one.set(3); cs = new HiddenColumns(); cs.hideColumns(one); assertEquals(1, cs.getNumberOfRegions()); + assertEquals(3, cs.getSize()); // split one.clear(2); cs = new HiddenColumns(); cs.hideColumns(one); assertEquals(2, cs.getNumberOfRegions()); + assertEquals(2, cs.getSize()); assertEquals(0, cs.visibleToAbsoluteColumn(0)); assertEquals(2, cs.visibleToAbsoluteColumn(1)); @@ -562,6 +570,7 @@ public class HiddenColumnsTest one.clear(1); cs = new HiddenColumns(); cs.hideColumns(one); + assertEquals(1, cs.getSize()); assertEquals(1, cs.getNumberOfRegions()); @@ -572,50 +581,6 @@ public class HiddenColumnsTest } @Test(groups = { "Functional" }) - public void hideColumns_BitSetAndRange() - { - HiddenColumns hc = new HiddenColumns(); - hc.hideColumns(3, 5); - hc.hideColumns(15, 20); - hc.hideColumns(45, 60); - - BitSet tohide = new BitSet(); - - // all unhidden if tohide is empty and range covers hidden - hc.hideColumns(tohide, 1, 70); - assertTrue(!hc.hasHiddenColumns()); - assertEquals(0, hc.getSize()); - - hc.hideColumns(3, 5); - hc.hideColumns(15, 20); - hc.hideColumns(45, 60); - assertEquals(25, hc.getSize()); - - // but not if range does not cover hidden - hc.hideColumns(tohide, 23, 40); - assertTrue(hc.hasHiddenColumns()); - assertEquals(25, hc.getSize()); - - // and partial unhide if range partially covers - hc.hideColumns(tohide, 1, 17); - Iterator it = hc.iterator(); - assertTrue(it.hasNext()); - int[] region = it.next(); - - assertEquals(18, region[0]); - assertEquals(20, region[1]); - - assertTrue(it.hasNext()); - region = it.next(); - - assertEquals(45, region[0]); - assertEquals(60, region[1]); - - assertFalse(it.hasNext()); - assertEquals(19, hc.getSize()); - } - - @Test(groups = { "Functional" }) public void testRegionsToString() { HiddenColumns hc = new HiddenColumns(); @@ -885,12 +850,14 @@ public class HiddenColumnsTest h.hideList(seq2.getInsertions()); assertTrue(h.equals(h2)); + assertEquals(0, h.getSize()); h.hideList(seq1.getInsertions()); h2.hideColumns(3, 5); h2.hideColumns(9, 9); h2.hideColumns(19, 20); assertTrue(h.equals(h2)); + assertEquals(6, h.getSize()); } @Test(groups = "Functional") @@ -937,6 +904,46 @@ public class HiddenColumnsTest h2.hideColumns(25, 27); assertTrue(h.equals(h2)); assertEquals(h.getSize(), h2.getSize()); + + HiddenColumns hc = new HiddenColumns(); + hc.hideColumns(3, 5); + hc.hideColumns(15, 20); + hc.hideColumns(45, 60); + + tohide = new BitSet(); + + // all unhidden if tohide is empty and range covers hidden + hc.hideColumns(tohide, 1, 70); + assertTrue(!hc.hasHiddenColumns()); + assertEquals(0, hc.getSize()); + + hc.hideColumns(3, 5); + hc.hideColumns(15, 20); + hc.hideColumns(45, 60); + assertEquals(25, hc.getSize()); + + // but not if range does not cover hidden + hc.hideColumns(tohide, 23, 40); + assertTrue(hc.hasHiddenColumns()); + assertEquals(25, hc.getSize()); + + // and partial unhide if range partially covers + hc.hideColumns(tohide, 1, 17); + Iterator it = hc.iterator(); + assertTrue(it.hasNext()); + int[] region = it.next(); + + assertEquals(18, region[0]); + assertEquals(20, region[1]); + + assertTrue(it.hasNext()); + region = it.next(); + + assertEquals(45, region[0]); + assertEquals(60, region[1]); + + assertFalse(it.hasNext()); + assertEquals(19, hc.getSize()); } @Test(groups = "Functional")