From 5469c2e5be5d08da09a45b978ea21ac8f6702b0b Mon Sep 17 00:00:00 2001 From: kiramt Date: Thu, 18 Jan 2018 14:12:08 +0000 Subject: [PATCH] JAL-2759 Updated test --- src/jalview/datamodel/HiddenColumns.java | 67 +++++++++++++------------ test/jalview/datamodel/HiddenColumnsTest.java | 30 ++++++++--- 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index d7628b7..55af3f8 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -1156,9 +1156,9 @@ public class HiddenColumns // make sure only bits between start and end are set if (!tohide.isEmpty()) { - tohide.clear(0, start - 1); - tohide.clear(Math.min(end + 1, tohide.length() - 1), - tohide.length() - 1); + tohide.clear(0, start); + tohide.clear(Math.min(end + 1, tohide.length() + 1), + tohide.length() + 1); } hideColumns(tohide); @@ -1178,42 +1178,45 @@ public class HiddenColumns { LOCK.writeLock().lock(); - HiddenCursorPosition pos = cursor.findRegionForColumn(start); - int index = pos.getRegionIndex(); - int startindex = index; // first index in hiddenColumns to remove - - if (index != -1 && index != hiddenColumns.size()) + if (!hiddenColumns.isEmpty()) { - // regionIndex is the region which either contains start - // or lies to the right of start - int[] region = hiddenColumns.get(index); - if (region[0] < start && region[1] >= start) + HiddenCursorPosition pos = cursor.findRegionForColumn(start); + int index = pos.getRegionIndex(); + int startindex = index; // first index in hiddenColumns to remove + + if (index != -1 && index != hiddenColumns.size()) { - // region contains start, truncate so that it ends just before start - region[1] = start - 1; - startindex++; + // regionIndex is the region which either contains start + // or lies to the right of start + int[] region = hiddenColumns.get(index); + if (region[0] < start && region[1] >= start) + { + // region contains start, truncate so that it ends just before start + region[1] = start - 1; + startindex++; + } } - } - - pos = cursor.findRegionForColumn(end); - index = pos.getRegionIndex(); - int endindex = index - 1; // last index in hiddenColumns to remove - if (index != -1 && index != hiddenColumns.size()) - { - // regionIndex is the region which either contains end - // or lies to the right of end - int[] region = hiddenColumns.get(index); - if (region[0] <= end && region[1] > end) + pos = cursor.findRegionForColumn(end); + index = pos.getRegionIndex(); + int endindex = index - 1; // last index in hiddenColumns to remove + + if (index != -1 && index != hiddenColumns.size()) { - // region contains end, truncate so that it starts just after end - region[0] = end + 1; + // regionIndex is the region which either contains end + // or lies to the right of end + int[] region = hiddenColumns.get(index); + if (region[0] <= end && region[1] > end) + { + // region contains end, truncate so that it starts just after end + region[0] = end + 1; + } } + + hiddenColumns.subList(startindex, endindex + 1).clear(); + cursor.resetCursor(hiddenColumns); + numColumns = 0; } - - hiddenColumns.subList(startindex, endindex + 1).clear(); - cursor.resetCursor(hiddenColumns); - numColumns = 0; } finally { LOCK.writeLock().unlock(); diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 462957b..3aadcb7 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -1160,7 +1160,7 @@ public class HiddenColumnsTest } @Test(groups = "Functional") - public void testHideColumns_BitSet() + public void testHideColumns_BitSet_range() { HiddenColumns h = new HiddenColumns(); HiddenColumns h2 = new HiddenColumns(); @@ -1169,16 +1169,34 @@ public class HiddenColumnsTest h.hideColumns(tohide); assertTrue(h.equals(h2)); - // NB in hideMarkedBits, the last bit is not set to hidden + // when setting bitset, first param is invlusive, second exclusive tohide.set(3, 6); tohide.set(9); - tohide.set(19, 21); - h.hideColumns(tohide); + tohide.set(15, 21); + h.hideColumns(tohide, 5, 23); - h2.hideColumns(3, 5); + h2.hideColumns(5, 5); h2.hideColumns(9, 9); - h2.hideColumns(19, 20); + h2.hideColumns(15, 20); + assertTrue(h.equals(h2)); + + tohide.clear(); + tohide.set(41); + h.hideColumns(tohide, 23, 30); + assertTrue(h.equals(h2)); + + tohide.set(41); + h.hideColumns(tohide, 30, 45); + h2.hideColumns(41, 41); assertTrue(h.equals(h2)); + + tohide.clear(); + tohide.set(25, 28); + h.hideColumns(tohide, 17, 50); + h2 = new HiddenColumns(); + h2.hideColumns(17, 20); + h2.hideColumns(25, 27); + h2.hideColumns(41, 41); } @Test(groups = "Functional") -- 1.7.10.2