+ HiddenColumns cs = new HiddenColumns();
+
+ // test that without hidden columns, offsetByVisibleColumns returns
+ // position n to left of provided position
+ long pos = cs.offsetByVisibleColumns(-3, 10);
+ assertEquals(7, pos);
+
+ // 0 returns same position
+ pos = cs.offsetByVisibleColumns(0, 10);
+ assertEquals(10, pos);
+
+ // overflow to left returns negative number
+ pos = cs.offsetByVisibleColumns(-3, 0);
+ assertEquals(-3, pos);
+
+ // test that with hidden columns to left of result column
+ // behaviour is the same as above
+ cs.hideColumns(1, 3);
+
+ // position n to left of provided position
+ pos = cs.offsetByVisibleColumns(-3, 10);
+ assertEquals(7, pos);
+
+ // 0 returns same position
+ pos = cs.offsetByVisibleColumns(0, 10);
+ assertEquals(10, pos);
+
+ // test with one set of hidden columns between start and required position
+ cs.hideColumns(12, 15);
+ pos = cs.offsetByVisibleColumns(-8, 17);
+ assertEquals(5, pos);
+
+ // test with two sets of hidden columns between start and required position
+ cs.hideColumns(20, 21);
+ pos = cs.offsetByVisibleColumns(-8, 23);
+ assertEquals(9, pos);
+
+ // repeat last 2 tests with no hidden columns to left of required position
+ ColumnSelection colsel = new ColumnSelection();
+ cs.revealAllHiddenColumns(colsel);
+
+ // test with one set of hidden columns between start and required position
+ cs.hideColumns(12, 15);
+ pos = cs.offsetByVisibleColumns(-8, 17);
+ assertEquals(5, pos);
+
+ // test with two sets of hidden columns between start and required position
+ cs.hideColumns(20, 21);
+ pos = cs.offsetByVisibleColumns(-8, 23);
+ assertEquals(9, pos);
+
+ // test with right (positive) offsets
+
+ // test that without hidden columns, offsetByVisibleColumns returns
+ // position n to right of provided position
+ pos = cs.offsetByVisibleColumns(3, 7);
+ assertEquals(10, pos);
+
+ // test that with hidden columns to left of result column
+ // behaviour is the same as above
+ cs.hideColumns(1, 3);
+
+ // test with one set of hidden columns between start and required position
+ cs.hideColumns(12, 15);
+ pos = cs.offsetByVisibleColumns(8, 5);
+ assertEquals(17, pos);
+
+ // test with two sets of hidden columns between start and required position
+ cs.hideColumns(20, 21);
+ pos = cs.offsetByVisibleColumns(8, 9);
+ assertEquals(23, pos);
+
+ // repeat last 2 tests with no hidden columns to left of required position
+ colsel = new ColumnSelection();
+ cs.revealAllHiddenColumns(colsel);
+
+ // test with one set of hidden columns between start and required position
+ cs.hideColumns(12, 15);
+ pos = cs.offsetByVisibleColumns(8, 5);
+ assertEquals(17, pos);
+
+ // test with two sets of hidden columns between start and required position
+ cs.hideColumns(20, 21);
+ pos = cs.offsetByVisibleColumns(8, 9);
+ assertEquals(23, pos);
+ }
+
+ @Test(groups = "Functional")
+ public void testBoundedIterator()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Iterator<int[]> it = h.getBoundedIterator(0, 10);
+
+ // no hidden columns = nothing to iterate over
+ assertFalse(it.hasNext());
+
+ // [start,end] contains all hidden columns
+ // all regions are returned
+ h.hideColumns(3, 10);
+ h.hideColumns(14, 16);
+ it = h.getBoundedIterator(0, 20);
+ assertTrue(it.hasNext());
+ int[] next = it.next();
+ assertEquals(3, next[0]);
+ assertEquals(10, next[1]);
+ next = it.next();
+ assertEquals(14, next[0]);
+ assertEquals(16, next[1]);
+ assertFalse(it.hasNext());
+
+ // [start,end] overlaps a region
+ // 1 region returned
+ it = h.getBoundedIterator(5, 7);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(3, next[0]);
+ assertEquals(10, next[1]);
+ assertFalse(it.hasNext());
+
+ // [start,end] fully contains 1 region and start of last
+ // - 2 regions returned
+ it = h.getBoundedIterator(3, 15);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(3, next[0]);
+ assertEquals(10, next[1]);
+ next = it.next();
+ assertEquals(14, next[0]);
+ assertEquals(16, next[1]);
+ assertFalse(it.hasNext());
+
+ // [start,end] contains end of first region and whole of last region
+ // - 2 regions returned
+ it = h.getBoundedIterator(4, 20);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(3, next[0]);
+ assertEquals(10, next[1]);
+ next = it.next();
+ assertEquals(14, next[0]);
+ assertEquals(16, next[1]);
+ assertFalse(it.hasNext());
+ }
+
+ @Test(groups = "Functional")
+ public void testBoundedStartIterator()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Iterator<Integer> it = h.getStartRegionIterator(0, 10);
+
+ // no hidden columns = nothing to iterate over
+ assertFalse(it.hasNext());
+
+ // [start,end] contains all hidden columns
+ // all regions are returned
+ h.hideColumns(3, 10);
+ h.hideColumns(14, 16);
+ it = h.getStartRegionIterator(0, 20);
+ assertTrue(it.hasNext());
+ int next = it.next();
+ assertEquals(3, next);
+ next = it.next();
+ assertEquals(6, next);
+ assertFalse(it.hasNext());
+
+ // [start,end] does not contain a start of a region
+ // no regions to iterate over
+ it = h.getStartRegionIterator(4, 5);
+ assertFalse(it.hasNext());
+
+ // [start,end] fully contains 1 region and start of last
+ // - 2 regions returned
+ it = h.getStartRegionIterator(3, 7);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(3, next);
+ next = it.next();
+ assertEquals(6, next);
+ assertFalse(it.hasNext());
+
+ // [start,end] contains whole of last region
+ // - 1 region returned
+ it = h.getStartRegionIterator(4, 20);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(6, next);
+ assertFalse(it.hasNext());
+ }
+
+ @Test(groups = "Functional")
+ public void testVisibleBlocksVisBoundsIterator()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Iterator<int[]> regions = h.getVisContigsIterator(0, 31, 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.getVisContigsIterator(0, 31, 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.getVisContigsIterator(0, 31, 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.getVisContigsIterator(0, 31, 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.getVisContigsIterator(0, 31, 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.getVisContigsIterator(0, 31, 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.getVisContigsIterator(0, 31, 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.getVisContigsIterator(0, 31, 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());
+ }
+
+ /*
+ * the VisibleColsIterator is tested elsewhere, this just tests that
+ * it can be retrieved from HiddenColumns
+ */
+ @Test(groups = "Functional")
+ public void testGetVisibleColsIterator()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Iterator<Integer> it = h.getVisibleColsIterator(0, 10);
+
+ assertTrue(it instanceof RangeElementsIterator);