import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Random;
h.hideColumns(0, 30);
result = h.subtractVisibleColumns(31, 0);
assertEquals(-31, result);
+ }
+ @Test(groups = "Functional")
+ public void testBoundedIterator()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Iterator<int[]> it = h.getBoundedIterator(0, 10, false);
+
+ // 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, false);
+ 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, false);
+ 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, false);
+ 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, false);
+ 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.getBoundedStartIterator(0, 10, false);
+
+ // 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.getBoundedStartIterator(0, 20, false);
+ 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.getBoundedStartIterator(4, 5, false);
+ assertFalse(it.hasNext());
+
+ // [start,end] fully contains 1 region and start of last
+ // - 2 regions returned
+ it = h.getBoundedStartIterator(3, 7, false);
+ 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.getBoundedStartIterator(4, 20, false);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(6, next);
+ assertFalse(it.hasNext());
+ }
}