2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import static org.testng.Assert.assertNull;
24 import static org.testng.AssertJUnit.assertEquals;
25 import static org.testng.AssertJUnit.assertFalse;
26 import static org.testng.AssertJUnit.assertTrue;
28 import jalview.analysis.AlignmentGenerator;
29 import jalview.gui.JvOptionPane;
30 import jalview.util.Comparison;
32 import java.util.Arrays;
33 import java.util.BitSet;
34 import java.util.Iterator;
35 import java.util.List;
36 import java.util.Random;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.Test;
41 public class HiddenColumnsTest
44 @BeforeClass(alwaysRun = true)
45 public void setUpJvOptionPane()
47 JvOptionPane.setInteractiveMode(false);
48 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 * Test the method which counts the number of hidden columns
54 @Test(groups = { "Functional" })
55 public void testGetSize()
57 HiddenColumns hidden = new HiddenColumns();
58 assertEquals(0, hidden.getSize());
60 hidden.hideColumns(3, 5);
61 assertEquals(3, hidden.getSize());
63 hidden.hideColumns(8, 8);
64 assertEquals(4, hidden.getSize());
66 hidden.hideColumns(9, 14);
67 assertEquals(10, hidden.getSize());
69 ColumnSelection cs = new ColumnSelection();
70 hidden.revealAllHiddenColumns(cs);
71 assertEquals(0, hidden.getSize());
75 * Test the method that finds the visible column position of an alignment
76 * column, allowing for hidden columns.
78 @Test(groups = { "Functional" })
79 public void testFindColumnPosition()
81 HiddenColumns cs = new HiddenColumns();
82 assertEquals(5, cs.findColumnPosition(5));
84 // hiding column 6 makes no difference
86 assertEquals(5, cs.findColumnPosition(5));
88 // hiding column 4 moves column 5 to column 4
90 assertEquals(4, cs.findColumnPosition(5));
92 // hiding column 4 moves column 4 to position 3
93 assertEquals(3, cs.findColumnPosition(4));
95 // hiding columns 1 and 2 moves column 5 to column 2
97 assertEquals(2, cs.findColumnPosition(5));
99 // check with > 1 hidden column regions
100 // where some columns are in the hidden regions
101 HiddenColumns cs2 = new HiddenColumns();
102 cs2.hideColumns(5, 10);
103 cs2.hideColumns(20, 27);
104 cs2.hideColumns(40, 44);
106 // hiding columns 5-10 and 20-27 moves column 8 to column 4
107 assertEquals(4, cs2.findColumnPosition(8));
109 // and moves column 24 to 13
110 assertEquals(13, cs2.findColumnPosition(24));
112 // and moves column 28 to 14
113 assertEquals(14, cs2.findColumnPosition(28));
115 // and moves column 40 to 25
116 assertEquals(25, cs2.findColumnPosition(40));
118 // check when hidden columns start at 0 that the visible column
120 HiddenColumns cs3 = new HiddenColumns();
121 cs3.hideColumns(0, 4);
122 assertEquals(0, cs3.findColumnPosition(2));
127 * Test the method that finds the visible column position a given distance
128 * before another column
130 @Test(groups = { "Functional" })
131 public void testFindColumnNToLeft()
133 HiddenColumns cs = new HiddenColumns();
135 // test that without hidden columns, findColumnNToLeft returns
136 // position n to left of provided position
137 long pos = cs.subtractVisibleColumns(3, 10);
138 assertEquals(7, pos);
140 // 0 returns same position
141 pos = cs.subtractVisibleColumns(0, 10);
142 assertEquals(10, pos);
144 // overflow to left returns negative number
145 pos = cs.subtractVisibleColumns(3, 0);
146 assertEquals(-3, pos);
148 // test that with hidden columns to left of result column
149 // behaviour is the same as above
150 cs.hideColumns(1, 3);
152 // position n to left of provided position
153 pos = cs.subtractVisibleColumns(3, 10);
154 assertEquals(7, pos);
156 // 0 returns same position
157 pos = cs.subtractVisibleColumns(0, 10);
158 assertEquals(10, pos);
160 // test with one set of hidden columns between start and required position
161 cs.hideColumns(12, 15);
162 pos = cs.subtractVisibleColumns(8, 17);
163 assertEquals(5, pos);
165 // test with two sets of hidden columns between start and required position
166 cs.hideColumns(20, 21);
167 pos = cs.subtractVisibleColumns(8, 23);
168 assertEquals(9, pos);
170 // repeat last 2 tests with no hidden columns to left of required position
171 ColumnSelection colsel = new ColumnSelection();
172 cs.revealAllHiddenColumns(colsel);
174 // test with one set of hidden columns between start and required position
175 cs.hideColumns(12, 15);
176 pos = cs.subtractVisibleColumns(8, 17);
177 assertEquals(5, pos);
179 // test with two sets of hidden columns between start and required position
180 cs.hideColumns(20, 21);
181 pos = cs.subtractVisibleColumns(8, 23);
182 assertEquals(9, pos);
186 @Test(groups = { "Functional" })
187 public void testGetVisibleContigs()
189 HiddenColumns cs = new HiddenColumns();
191 List<int[]> visible = cs.getVisibleContigs(3, 10);
192 assertEquals("[3, 9]", Arrays.toString(visible.get(0)));
194 cs.hideColumns(3, 6);
195 cs.hideColumns(8, 9);
196 cs.hideColumns(12, 12);
198 // Test both ends visible region
200 // start position is inclusive, end position exclusive
201 visible = cs.getVisibleContigs(1, 13);
202 assertEquals("[1, 2]", Arrays.toString(visible.get(0)));
203 assertEquals("[7, 7]", Arrays.toString(visible.get(1)));
204 assertEquals("[10, 11]", Arrays.toString(visible.get(2)));
206 // Test start hidden, end visible
207 visible = cs.getVisibleContigs(4, 14);
208 assertEquals("[7, 7]", Arrays.toString(visible.get(0)));
209 assertEquals("[10, 11]", Arrays.toString(visible.get(1)));
210 assertEquals("[13, 13]", Arrays.toString(visible.get(2)));
212 // Test start hidden, end hidden
213 visible = cs.getVisibleContigs(3, 10);
214 assertEquals("[7, 7]", Arrays.toString(visible.get(0)));
216 // Test start visible, end hidden
217 visible = cs.getVisibleContigs(0, 13);
218 assertEquals("[0, 2]", Arrays.toString(visible.get(0)));
219 assertEquals("[7, 7]", Arrays.toString(visible.get(1)));
220 assertEquals("[10, 11]", Arrays.toString(visible.get(2)));
223 visible = cs.getVisibleContigs(4, 6);
224 assertEquals(0, visible.size());
227 @Test(groups = { "Functional" })
228 public void testEquals()
230 HiddenColumns cs = new HiddenColumns();
231 cs.hideColumns(5, 9);
233 // a different set of hidden columns
234 HiddenColumns cs2 = new HiddenColumns();
236 // with no hidden columns
237 assertFalse(cs.equals(cs2));
238 assertFalse(cs2.equals(cs));
240 // with hidden columns added in a different order
241 cs2.hideColumns(6, 9);
242 cs2.hideColumns(5, 8);
244 assertTrue(cs.equals(cs2));
245 assertTrue(cs.equals(cs));
246 assertTrue(cs2.equals(cs));
247 assertTrue(cs2.equals(cs2));
250 @Test(groups = "Functional")
251 public void testCopyConstructor()
253 HiddenColumns cs = new HiddenColumns();
254 cs.hideColumns(10, 11);
255 cs.hideColumns(5, 7);
256 Iterator<int[]> regions = cs.iterator();
257 assertEquals("[5, 7]",
258 Arrays.toString(regions.next()));
260 HiddenColumns cs2 = new HiddenColumns(cs);
261 regions = cs2.iterator();
262 assertTrue(cs2.hasHiddenColumns());
263 assertEquals(2, cs2.getNumberOfRegions());
264 // hidden columns are held in column order
265 assertEquals("[5, 7]",
266 Arrays.toString(regions.next()));
267 assertEquals("[10, 11]",
268 Arrays.toString(regions.next()));
271 @Test(groups = "Functional")
272 public void testCopyConstructor2()
274 HiddenColumns cs = new HiddenColumns();
275 cs.hideColumns(10, 11);
276 cs.hideColumns(5, 7);
278 HiddenColumns cs2 = new HiddenColumns(cs, 3, 9, 1);
279 assertTrue(cs2.hasHiddenColumns());
280 Iterator<int[]> regions = cs2.iterator();
282 // only [5,7] returned, offset by 1
283 assertEquals("[4, 6]",
284 Arrays.toString(regions.next()));
285 assertEquals(3, cs2.getSize());
287 cs2 = new HiddenColumns(cs, 8, 15, 4);
288 regions = cs2.iterator();
289 assertTrue(cs2.hasHiddenColumns());
291 // only [10,11] returned, offset by 4
292 assertEquals("[6, 7]",
293 Arrays.toString(regions.next()));
294 assertEquals(2, cs2.getSize());
296 cs2 = new HiddenColumns(cs, 6, 10, 4);
297 assertFalse(cs2.hasHiddenColumns());
301 * Test the code used to locate the reference sequence ruler origin
303 @Test(groups = { "Functional" })
304 public void testLocateVisibleBoundsofSequence()
306 // create random alignment
307 AlignmentGenerator gen = new AlignmentGenerator(false);
308 AlignmentI al = gen.generate(50, 20, 123, 5, 5);
310 HiddenColumns cs = al.getHiddenColumns();
311 ColumnSelection colsel = new ColumnSelection();
313 SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
314 assertEquals(2, seq.findIndex(seq.getStart()));
318 Arrays.toString(new int[]
319 { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getStart()) - 1,
320 seq.findIndex(seq.getEnd()) - 1 }),
321 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
323 // hidden column on gap after end of sequence - should not affect bounds
324 colsel.hideSelectedColumns(13, al.getHiddenColumns());
326 Arrays.toString(new int[]
327 { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getStart()) - 1,
328 seq.findIndex(seq.getEnd()) - 1 }),
329 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
331 cs.revealAllHiddenColumns(colsel);
332 // hidden column on gap before beginning of sequence - should vis bounds by
334 colsel.hideSelectedColumns(0, al.getHiddenColumns());
336 Arrays.toString(new int[]
337 { seq.findIndex(seq.getStart()) - 2, seq.findIndex(seq.getStart()) - 1,
338 seq.findIndex(seq.getEnd()) - 1 }),
339 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
341 cs.revealAllHiddenColumns(colsel);
342 // hide columns around most of sequence - leave one residue remaining
343 cs.hideColumns(1, 3);
344 cs.hideColumns(6, 11);
346 cs.getVisibleSequenceStrings(0, 5, new SequenceI[]
352 { 1, seq.findIndex(seq.getStart()) - 1,
353 seq.findIndex(seq.getEnd()) - 1 }),
354 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
355 cs.revealAllHiddenColumns(colsel);
357 // hide whole sequence - should just get location of hidden region
358 // containing sequence
359 cs.hideColumns(1, 11);
363 { 0, seq.findIndex(seq.getStart()) - 1,
364 seq.findIndex(seq.getEnd()) - 1 }),
365 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
367 cs.revealAllHiddenColumns(colsel);
368 cs.hideColumns(0, 15);
371 { 0, seq.findIndex(seq.getStart()) - 1,
372 seq.findIndex(seq.getEnd()) - 1 }),
373 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
375 SequenceI seq2 = new Sequence("RefSeq2", "-------A-SD-ASD--E---");
377 cs.revealAllHiddenColumns(colsel);
378 cs.hideColumns(7, 17);
382 { 0, seq2.findIndex(seq2.getStart()) - 1,
383 seq2.findIndex(seq2.getEnd()) - 1 }),
384 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
386 cs.revealAllHiddenColumns(colsel);
387 cs.hideColumns(3, 17);
391 { 0, seq2.findIndex(seq2.getStart()) - 1,
392 seq2.findIndex(seq2.getEnd()) - 1 }),
393 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
395 cs.revealAllHiddenColumns(colsel);
396 cs.hideColumns(3, 19);
400 { 0, seq2.findIndex(seq2.getStart()) - 1,
401 seq2.findIndex(seq2.getEnd()) - 1 }),
402 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
404 cs.revealAllHiddenColumns(colsel);
405 cs.hideColumns(0, 0);
406 int[] test = cs.locateVisibleBoundsOfSequence(seq);
407 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
408 Arrays.toString(test));
410 cs.revealAllHiddenColumns(colsel);
411 cs.hideColumns(0, 1);
412 test = cs.locateVisibleBoundsOfSequence(seq);
413 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
414 Arrays.toString(test));
416 cs.revealAllHiddenColumns(colsel);
417 cs.hideColumns(0, 2);
418 test = cs.locateVisibleBoundsOfSequence(seq);
419 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
420 Arrays.toString(test));
422 cs.revealAllHiddenColumns(colsel);
423 cs.hideColumns(1, 1);
424 test = cs.locateVisibleBoundsOfSequence(seq);
425 assertEquals(Arrays.toString(new int[] { 2, 1, 11 }),
426 Arrays.toString(test));
428 cs.revealAllHiddenColumns(colsel);
429 cs.hideColumns(1, 2);
430 test = cs.locateVisibleBoundsOfSequence(seq);
431 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
432 Arrays.toString(test));
434 cs.revealAllHiddenColumns(colsel);
435 cs.hideColumns(1, 3);
436 test = cs.locateVisibleBoundsOfSequence(seq);
437 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
438 Arrays.toString(test));
440 cs.revealAllHiddenColumns(colsel);
441 cs.hideColumns(0, 2);
442 cs.hideColumns(5, 6);
443 test = cs.locateVisibleBoundsOfSequence(seq);
444 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
445 Arrays.toString(test));
447 cs.revealAllHiddenColumns(colsel);
448 cs.hideColumns(0, 2);
449 cs.hideColumns(5, 6);
450 cs.hideColumns(9, 10);
451 test = cs.locateVisibleBoundsOfSequence(seq);
452 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
453 Arrays.toString(test));
455 cs.revealAllHiddenColumns(colsel);
456 cs.hideColumns(0, 2);
457 cs.hideColumns(7, 11);
458 test = cs.locateVisibleBoundsOfSequence(seq);
459 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
460 Arrays.toString(test));
462 cs.revealAllHiddenColumns(colsel);
463 cs.hideColumns(2, 4);
464 cs.hideColumns(7, 11);
465 test = cs.locateVisibleBoundsOfSequence(seq);
466 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
467 Arrays.toString(test));
469 cs.revealAllHiddenColumns(colsel);
470 cs.hideColumns(2, 4);
471 cs.hideColumns(7, 12);
472 test = cs.locateVisibleBoundsOfSequence(seq);
473 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
474 Arrays.toString(test));
476 cs.revealAllHiddenColumns(colsel);
477 cs.hideColumns(1, 11);
478 test = cs.locateVisibleBoundsOfSequence(seq);
479 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
480 Arrays.toString(test));
482 cs.revealAllHiddenColumns(colsel);
483 cs.hideColumns(0, 12);
484 test = cs.locateVisibleBoundsOfSequence(seq);
485 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
486 Arrays.toString(test));
488 cs.revealAllHiddenColumns(colsel);
489 cs.hideColumns(0, 4);
490 cs.hideColumns(6, 12);
491 test = cs.locateVisibleBoundsOfSequence(seq);
492 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
493 Arrays.toString(test));
495 cs.revealAllHiddenColumns(colsel);
496 cs.hideColumns(0, 1);
497 cs.hideColumns(3, 12);
498 test = cs.locateVisibleBoundsOfSequence(seq);
499 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
500 Arrays.toString(test));
502 // These tests cover different behaviour to original
503 // locateVisibleBoundsOfSequence
504 // Previously first values of each were 3,9 and 6 respectively.
505 cs.revealAllHiddenColumns(colsel);
506 cs.hideColumns(3, 14);
507 cs.hideColumns(17, 19);
511 { 3, seq2.findIndex(seq2.getStart()) - 1,
512 seq2.findIndex(seq2.getEnd()) - 1 }),
513 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
515 cs.revealAllHiddenColumns(colsel);
516 cs.hideColumns(3, 7);
517 cs.hideColumns(9, 14);
518 cs.hideColumns(17, 19);
522 { 9, seq2.findIndex(seq2.getStart()) - 1,
523 seq2.findIndex(seq2.getEnd()) - 1 }),
524 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
526 cs.revealAllHiddenColumns(colsel);
527 cs.hideColumns(0, 1);
528 cs.hideColumns(3, 4);
529 cs.hideColumns(6, 8);
530 cs.hideColumns(10, 12);
531 test = cs.locateVisibleBoundsOfSequence(seq);
532 assertEquals(Arrays.toString(new int[] { 6, 1, 11 }),
533 Arrays.toString(test));
537 @Test(groups = { "Functional" })
538 public void testLocateVisibleBoundsPathologicals()
540 // test some pathological cases we missed
541 AlignmentI al = new Alignment(
543 { new Sequence("refseqGaptest", "KTDVTI----------NFI-----G----L") });
544 HiddenColumns cs = new HiddenColumns();
545 cs.hideInsertionsFor(al.getSequenceAt(0));
547 + al.getSequenceAt(0).getCharAt(cs.adjustForHiddenColumns(9)));
551 @Test(groups = { "Functional" })
552 public void testHideColumns()
554 // create random alignment
555 AlignmentGenerator gen = new AlignmentGenerator(false);
556 AlignmentI al = gen.generate(50, 20, 123, 5, 5);
558 ColumnSelection colsel = new ColumnSelection();
559 HiddenColumns cs = al.getHiddenColumns();
560 colsel.hideSelectedColumns(5, al.getHiddenColumns());
561 Iterator<int[]> regions = cs.iterator();
562 assertEquals(1, cs.getNumberOfRegions());
563 assertEquals("[5, 5]", Arrays.toString(regions.next()));
565 colsel.hideSelectedColumns(3, al.getHiddenColumns());
566 regions = cs.iterator();
567 assertEquals(2, cs.getNumberOfRegions());
568 // two hidden ranges, in order:
569 assertEquals("[3, 3]", Arrays.toString(regions.next()));
570 assertEquals("[5, 5]", Arrays.toString(regions.next()));
572 // hiding column 4 expands [3, 3] to [3, 4]
573 // and merges to [5, 5] to make [3, 5]
574 colsel.hideSelectedColumns(4, al.getHiddenColumns());
575 regions = cs.iterator();
576 assertEquals(1, cs.getNumberOfRegions());
577 assertEquals("[3, 5]", Arrays.toString(regions.next()));
579 // clear hidden columns (note they are added to selected)
580 cs.revealAllHiddenColumns(colsel);
581 // it is now actually null but getter returns an empty list
582 assertEquals(0, cs.getNumberOfRegions());
584 cs.hideColumns(3, 6);
585 regions = cs.iterator();
586 int[] firstHiddenRange = regions.next();
587 assertEquals("[3, 6]", Arrays.toString(firstHiddenRange));
589 // adding a subrange of already hidden should do nothing
590 cs.hideColumns(4, 5);
591 regions = cs.iterator();
592 assertEquals(1, cs.getNumberOfRegions());
593 assertEquals("[3, 6]",
594 Arrays.toString(regions.next()));
595 cs.hideColumns(3, 5);
596 regions = cs.iterator();
597 assertEquals(1, cs.getNumberOfRegions());
598 assertEquals("[3, 6]",
599 Arrays.toString(regions.next()));
600 cs.hideColumns(4, 6);
601 regions = cs.iterator();
602 assertEquals(1, cs.getNumberOfRegions());
603 assertEquals("[3, 6]",
604 Arrays.toString(regions.next()));
605 cs.hideColumns(3, 6);
606 regions = cs.iterator();
607 assertEquals(1, cs.getNumberOfRegions());
608 assertEquals("[3, 6]",
609 Arrays.toString(regions.next()));
611 cs.revealAllHiddenColumns(colsel);
612 cs.hideColumns(2, 4);
613 regions = cs.iterator();
614 assertEquals(1, cs.getNumberOfRegions());
615 assertEquals("[2, 4]", Arrays.toString(regions.next()));
617 // extend contiguous with 2 positions overlap
618 cs.hideColumns(3, 5);
619 regions = cs.iterator();
620 assertEquals(1, cs.getNumberOfRegions());
621 assertEquals("[2, 5]", Arrays.toString(regions.next()));
623 // extend contiguous with 1 position overlap
624 cs.hideColumns(5, 6);
625 regions = cs.iterator();
626 assertEquals(1, cs.getNumberOfRegions());
627 assertEquals("[2, 6]", Arrays.toString(regions.next()));
629 // extend contiguous with overlap both ends:
630 cs.hideColumns(1, 7);
631 regions = cs.iterator();
632 assertEquals(1, cs.getNumberOfRegions());
633 assertEquals("[1, 7]", Arrays.toString(regions.next()));
637 * Test the method that reveals a range of hidden columns given the start
638 * column of the range
640 @Test(groups = { "Functional" })
641 public void testRevealHiddenColumns()
643 ColumnSelection colsel = new ColumnSelection();
644 HiddenColumns cs = new HiddenColumns();
645 cs.hideColumns(5, 8);
646 colsel.addElement(10);
647 cs.revealHiddenColumns(5, colsel);
649 // hiddenColumns now empty
650 assertEquals(0, cs.getSize());
652 // revealed columns are marked as selected (added to selection):
653 assertEquals("[10, 5, 6, 7, 8]", colsel.getSelected().toString());
655 // calling with a column other than the range start does nothing:
656 colsel = new ColumnSelection();
657 cs = new HiddenColumns();
658 cs.hideColumns(5, 8);
660 int prevSize = cs.getSize();
661 cs.revealHiddenColumns(6, colsel);
662 assertEquals(prevSize, cs.getSize());
663 assertTrue(colsel.getSelected().isEmpty());
666 @Test(groups = { "Functional" })
667 public void testRevealAllHiddenColumns()
669 HiddenColumns hidden = new HiddenColumns();
670 ColumnSelection colsel = new ColumnSelection();
671 hidden.hideColumns(5, 8);
672 hidden.hideColumns(2, 3);
673 colsel.addElement(11);
674 colsel.addElement(1);
675 hidden.revealAllHiddenColumns(colsel);
678 * revealing hidden columns adds them (in order) to the (unordered)
682 // hiddenColumns now empty
683 assertEquals(0, hidden.getSize());
685 assertEquals("[11, 1, 2, 3, 5, 6, 7, 8]",
686 colsel.getSelected().toString());
689 @Test(groups = { "Functional" })
690 public void testIsVisible()
692 HiddenColumns cs = new HiddenColumns();
693 cs.hideColumns(2, 4);
694 cs.hideColumns(6, 7);
695 assertTrue(cs.isVisible(0));
696 assertTrue(cs.isVisible(-99));
697 assertTrue(cs.isVisible(1));
698 assertFalse(cs.isVisible(2));
699 assertFalse(cs.isVisible(3));
700 assertFalse(cs.isVisible(4));
701 assertTrue(cs.isVisible(5));
702 assertFalse(cs.isVisible(6));
703 assertFalse(cs.isVisible(7));
707 * Test for the case when a hidden range encloses more one already hidden
710 @Test(groups = { "Functional" })
711 public void testHideColumns_subsumingHidden()
714 * JAL-2370 bug scenario:
715 * two hidden ranges subsumed by a third
717 HiddenColumns cs = new HiddenColumns();
718 cs.hideColumns(49, 59);
719 cs.hideColumns(69, 79);
720 Iterator<int[]> regions = cs.iterator();
721 assertEquals(2, cs.getNumberOfRegions());
722 assertEquals("[49, 59]", Arrays.toString(regions.next()));
723 assertEquals("[69, 79]", Arrays.toString(regions.next()));
725 cs.hideColumns(48, 80);
726 regions = cs.iterator();
727 assertEquals(1, cs.getNumberOfRegions());
728 assertEquals("[48, 80]", Arrays.toString(regions.next()));
731 * another...joining hidden ranges
733 cs = new HiddenColumns();
734 cs.hideColumns(10, 20);
735 cs.hideColumns(30, 40);
736 cs.hideColumns(50, 60);
737 // hiding 21-49 should merge to one range
738 cs.hideColumns(21, 49);
739 regions = cs.iterator();
740 assertEquals(1, cs.getNumberOfRegions());
741 assertEquals("[10, 60]", Arrays.toString(regions.next()));
744 * another...left overlap, subsumption, right overlap,
745 * no overlap of existing hidden ranges
747 cs = new HiddenColumns();
748 cs.hideColumns(10, 20);
749 cs.hideColumns(10, 20);
750 cs.hideColumns(30, 35);
751 cs.hideColumns(40, 50);
752 cs.hideColumns(60, 70);
754 cs.hideColumns(15, 45);
755 regions = cs.iterator();
756 assertEquals(2, cs.getNumberOfRegions());
757 assertEquals("[10, 50]", Arrays.toString(regions.next()));
758 assertEquals("[60, 70]", Arrays.toString(regions.next()));
761 @Test(groups = { "Functional" })
762 public void testHideBitset()
766 BitSet one = new BitSet();
770 cs = new HiddenColumns();
771 cs.hideMarkedBits(one);
772 assertEquals(1, cs.getNumberOfRegions());
775 cs = new HiddenColumns();
776 cs.hideMarkedBits(one);
777 assertEquals(1, cs.getNumberOfRegions());
780 cs = new HiddenColumns();
781 cs.hideMarkedBits(one);
782 assertEquals(1, cs.getNumberOfRegions());
786 cs = new HiddenColumns();
787 cs.hideMarkedBits(one);
788 assertEquals(2, cs.getNumberOfRegions());
790 assertEquals(0, cs.adjustForHiddenColumns(0));
791 assertEquals(2, cs.adjustForHiddenColumns(1));
792 assertEquals(4, cs.adjustForHiddenColumns(2));
796 cs = new HiddenColumns();
797 cs.hideMarkedBits(one);
799 assertEquals(1, cs.getNumberOfRegions());
801 assertEquals(0, cs.adjustForHiddenColumns(0));
802 assertEquals(1, cs.adjustForHiddenColumns(1));
803 assertEquals(2, cs.adjustForHiddenColumns(2));
804 assertEquals(4, cs.adjustForHiddenColumns(3));
807 @Test(groups = { "Functional" })
808 public void testMarkHiddenRegions()
810 BitSet toMark, fromMark;
811 long seed = -3241532;
812 Random number = new Random(seed);
813 for (int n = 0; n < 1000; n++)
815 // create a random bitfield
818 { number.nextLong(), number.nextLong(), number.nextLong() });
819 toMark.set(n * number.nextInt(10), n * (25 + number.nextInt(25)));
820 HiddenColumns hc = new HiddenColumns();
821 hc.hideMarkedBits(toMark);
823 // see if we can recover bitfield
824 hc.markHiddenRegions(fromMark = new BitSet());
825 assertEquals(toMark, fromMark);
829 @Test(groups = { "Functional" })
830 public void testFindHiddenRegionPositions()
832 HiddenColumns hc = new HiddenColumns();
834 List<Integer> positions = hc.findHiddenRegionPositions(0, 20);
835 assertTrue(positions.isEmpty());
837 hc.hideColumns(3, 7);
838 hc.hideColumns(10, 10);
839 hc.hideColumns(14, 15);
841 positions = hc.findHiddenRegionPositions(0, 20);
842 assertEquals(3, positions.size());
843 assertEquals(3, positions.get(0).intValue());
844 assertEquals(5, positions.get(1).intValue());
845 assertEquals(8, positions.get(2).intValue());
847 positions = hc.findHiddenRegionPositions(7, 20);
848 assertEquals(2, positions.size());
849 assertEquals(5, positions.get(0).intValue());
850 assertEquals(8, positions.get(1).intValue());
852 positions = hc.findHiddenRegionPositions(11, 13);
853 assertEquals(0, positions.size());
855 positions = hc.findHiddenRegionPositions(7, 20);
856 assertEquals(2, positions.size());
857 assertEquals(5, positions.get(0).intValue());
858 assertEquals(8, positions.get(1).intValue());
860 positions = hc.findHiddenRegionPositions(0, 1);
861 assertEquals(0, positions.size());
863 positions = hc.findHiddenRegionPositions(17, 20);
864 assertEquals(0, positions.size());
866 positions = hc.findHiddenRegionPositions(10, 15);
867 assertEquals(2, positions.size());
868 assertEquals(5, positions.get(0).intValue());
869 assertEquals(8, positions.get(1).intValue());
872 @Test(groups = { "Functional" })
873 public void testRegionsToString()
875 HiddenColumns hc = new HiddenColumns();
877 String result = hc.regionsToString(",", "--");
878 assertEquals("", result);
880 hc.hideColumns(3, 7);
881 hc.hideColumns(10, 10);
882 hc.hideColumns(14, 15);
884 result = hc.regionsToString(",", "--");
885 assertEquals("3--7,10--10,14--15", result);
888 @Test(groups = "Functional")
889 public void testGetVisibleStartAndEndIndexTest()
891 Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
892 AlignmentI align = new Alignment(new SequenceI[] { seq });
893 HiddenColumns hc = new HiddenColumns();
895 int[] startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
896 assertEquals(0, startEnd[0]);
897 assertEquals(25, startEnd[1]);
899 hc.hideColumns(0, 0);
900 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
901 assertEquals(1, startEnd[0]);
902 assertEquals(25, startEnd[1]);
904 hc.hideColumns(6, 9);
905 hc.hideColumns(11, 12);
906 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
907 assertEquals(1, startEnd[0]);
908 assertEquals(25, startEnd[1]);
910 hc.hideColumns(24, 25);
911 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
912 System.out.println(startEnd[0] + " : " + startEnd[1]);
913 assertEquals(1, startEnd[0]);
914 assertEquals(23, startEnd[1]);
917 @Test(groups = "Functional")
918 public void testGetRegionWithEdgeAtRes()
920 HiddenColumns hc = new HiddenColumns();
922 int[] result = hc.getRegionWithEdgeAtRes(5);
925 hc.hideColumns(3, 7);
926 hc.hideColumns(10, 10);
927 hc.hideColumns(14, 15);
929 result = hc.getRegionWithEdgeAtRes(2);
930 assertEquals(3, result[0]);
931 assertEquals(7, result[1]);
933 result = hc.getRegionWithEdgeAtRes(5);
934 assertEquals(10, result[0]);
935 assertEquals(10, result[1]);
937 result = hc.getRegionWithEdgeAtRes(6);
940 result = hc.getRegionWithEdgeAtRes(0);
943 result = hc.getRegionWithEdgeAtRes(7);
944 assertEquals(14, result[0]);
945 assertEquals(15, result[1]);
947 result = hc.getRegionWithEdgeAtRes(8);
948 assertEquals(14, result[0]);
949 assertEquals(15, result[1]);
952 @Test(groups = "Functional")
953 public void testPropagateInsertions()
955 // create an alignment with no gaps - this will be the profile seq and other
957 AlignmentGenerator gen = new AlignmentGenerator(false);
958 AlignmentI al = gen.generate(25, 10, 1234, 0, 0);
960 // get the profileseq
961 SequenceI profileseq = al.getSequenceAt(0);
962 SequenceI gappedseq = new Sequence(profileseq);
963 gappedseq.insertCharAt(5, al.getGapCharacter());
964 gappedseq.insertCharAt(6, al.getGapCharacter());
965 gappedseq.insertCharAt(7, al.getGapCharacter());
966 gappedseq.insertCharAt(8, al.getGapCharacter());
968 // create an alignment view with the gapped sequence
969 SequenceI[] seqs = new SequenceI[1];
971 AlignmentI newal = new Alignment(seqs);
972 HiddenColumns hidden = new HiddenColumns();
973 hidden.hideColumns(15, 17);
975 AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
978 // confirm that original contigs are as expected
979 List<int[]> visible = hidden.getVisibleContigs(0, 25);
980 assertEquals("[0, 14]", Arrays.toString(visible.get(0)));
981 assertEquals("[18, 24]", Arrays.toString(visible.get(1)));
983 // propagate insertions
984 HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
987 // confirm that the contigs have changed to account for the gaps
988 visible = result.getVisibleContigs(0, 25);
989 assertEquals("[0, 10]", Arrays.toString(visible.get(0)));
990 assertEquals("[14, 24]", Arrays.toString(visible.get(1)));
992 // confirm the alignment has been changed so that the other sequences have
993 // gaps inserted where the columns are hidden
994 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[10]));
995 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[11]));
996 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[12]));
997 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[13]));
998 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[14]));
1002 @Test(groups = "Functional")
1003 public void testPropagateInsertionsOverlap()
1005 // test propagateInsertions where gaps and hiddenColumns overlap
1007 // create an alignment with no gaps - this will be the profile seq and other
1009 AlignmentGenerator gen = new AlignmentGenerator(false);
1010 AlignmentI al = gen.generate(20, 10, 1234, 0, 0);
1012 // get the profileseq
1013 SequenceI profileseq = al.getSequenceAt(0);
1014 SequenceI gappedseq = new Sequence(profileseq);
1015 gappedseq.insertCharAt(5, al.getGapCharacter());
1016 gappedseq.insertCharAt(6, al.getGapCharacter());
1017 gappedseq.insertCharAt(7, al.getGapCharacter());
1018 gappedseq.insertCharAt(8, al.getGapCharacter());
1020 // create an alignment view with the gapped sequence
1021 SequenceI[] seqs = new SequenceI[1];
1022 seqs[0] = gappedseq;
1023 AlignmentI newal = new Alignment(seqs);
1025 // hide columns so that some overlap with the gaps
1026 HiddenColumns hidden = new HiddenColumns();
1027 hidden.hideColumns(7, 10);
1029 AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
1032 // confirm that original contigs are as expected
1033 List<int[]> visible = hidden.getVisibleContigs(0, 20);
1034 assertEquals("[0, 6]", Arrays.toString(visible.get(0)));
1035 assertEquals("[11, 19]", Arrays.toString(visible.get(1)));
1037 // propagate insertions
1038 HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
1041 // confirm that the contigs have changed to account for the gaps
1042 visible = result.getVisibleContigs(0, 20);
1043 assertEquals("[0, 4]", Arrays.toString(visible.get(0)));
1044 assertEquals("[7, 19]", Arrays.toString(visible.get(1)));
1046 // confirm the alignment has been changed so that the other sequences have
1047 // gaps inserted where the columns are hidden
1048 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[4]));
1049 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[5]));
1050 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[6]));
1051 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[7]));
1054 @Test(groups = "Functional")
1055 public void testHasHiddenColumns()
1057 HiddenColumns h = new HiddenColumns();
1059 // new HiddenColumns2 has no hidden cols
1060 assertFalse(h.hasHiddenColumns());
1062 // some columns hidden, returns true
1063 h.hideColumns(5, 10);
1064 assertTrue(h.hasHiddenColumns());
1066 // reveal columns, no hidden cols again
1067 ColumnSelection sel = new ColumnSelection();
1068 h.revealAllHiddenColumns(sel);
1069 assertFalse(h.hasHiddenColumns());
1072 @Test(groups = "Functional")
1073 public void testHasManyHiddenColumns()
1075 HiddenColumns h = new HiddenColumns();
1077 // new HiddenColumns2 has no hidden cols
1078 assertFalse(h.hasManyHiddenColumns());
1080 // one set of columns hidden, returns false
1081 h.hideColumns(5, 10);
1082 assertFalse(h.hasManyHiddenColumns());
1084 // two sets hidden, returns true
1085 h.hideColumns(15, 17);
1086 assertTrue(h.hasManyHiddenColumns());
1088 // back to one block, asserts false
1089 h.hideColumns(11, 14);
1090 assertFalse(h.hasManyHiddenColumns());
1093 @Test(groups = "Functional")
1094 public void testAdjustForHiddenColumns()
1096 HiddenColumns h = new HiddenColumns();
1097 // returns input value when there are no hidden columns
1098 assertEquals(10, h.adjustForHiddenColumns(10));
1100 h.hideColumns(20, 30);
1101 assertEquals(10, h.adjustForHiddenColumns(10));
1102 assertEquals(20 + 11, h.adjustForHiddenColumns(20));
1103 assertEquals(35 + 11, h.adjustForHiddenColumns(35));
1105 h.hideColumns(5, 7);
1106 assertEquals(10 + 3, h.adjustForHiddenColumns(10));
1107 assertEquals(20 + 14, h.adjustForHiddenColumns(20));
1108 assertEquals(35 + 14, h.adjustForHiddenColumns(35));
1110 ColumnSelection sel = new ColumnSelection();
1111 h.revealAllHiddenColumns(sel);
1112 h.hideColumns(0, 1);
1113 assertEquals(4, h.adjustForHiddenColumns(2));
1116 @Test(groups = "Functional")
1117 public void testGetHiddenBoundaryLeft()
1119 HiddenColumns h = new HiddenColumns();
1121 // returns same value if no hidden cols
1122 assertEquals(3, h.getHiddenBoundaryLeft(3));
1124 h.hideColumns(5, 10);
1125 assertEquals(10, h.getHiddenBoundaryLeft(15));
1126 assertEquals(3, h.getHiddenBoundaryLeft(3));
1127 assertEquals(7, h.getHiddenBoundaryLeft(7));
1129 h.hideColumns(15, 20);
1130 assertEquals(10, h.getHiddenBoundaryLeft(15));
1131 assertEquals(20, h.getHiddenBoundaryLeft(21));
1134 @Test(groups = "Functional")
1135 public void testGetHiddenBoundaryRight()
1137 HiddenColumns h = new HiddenColumns();
1139 // returns same value if no hidden cols
1140 assertEquals(3, h.getHiddenBoundaryRight(3));
1142 h.hideColumns(5, 10);
1143 assertEquals(5, h.getHiddenBoundaryRight(3));
1144 assertEquals(15, h.getHiddenBoundaryRight(15));
1145 assertEquals(7, h.getHiddenBoundaryRight(7));
1147 h.hideColumns(15, 20);
1148 assertEquals(15, h.getHiddenBoundaryRight(7));
1149 assertEquals(15, h.getHiddenBoundaryRight(14));
1152 @Test(groups = "Functional")
1153 public void testIterator()
1155 HiddenColumns h = new HiddenColumns();
1156 Iterator<int[]> result = h.iterator();
1157 assertFalse(result.hasNext());
1159 h.hideColumns(5, 10);
1160 result = h.iterator();
1161 int[] next = result.next();
1162 assertEquals(5, next[0]);
1163 assertEquals(10, next[1]);
1164 assertFalse(result.hasNext());
1166 h.hideColumns(22, 23);
1167 result = h.iterator();
1168 next = result.next();
1169 assertEquals(5, next[0]);
1170 assertEquals(10, next[1]);
1171 next = result.next();
1172 assertEquals(22, next[0]);
1173 assertEquals(23, next[1]);
1174 assertFalse(result.hasNext());
1176 // test for only one hidden region at start of alignment
1177 ColumnSelection sel = new ColumnSelection();
1178 h.revealAllHiddenColumns(sel);
1179 h.hideColumns(0, 1);
1180 result = h.iterator();
1181 next = result.next();
1182 assertEquals(0, next[0]);
1183 assertEquals(1, next[1]);
1184 assertFalse(result.hasNext());
1187 @Test(groups = "Functional")
1188 public void testGetVisibleSequenceStrings()
1190 HiddenColumns h = new HiddenColumns();
1191 SequenceI seq1 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
1192 SequenceI seq2 = new Sequence("TEST2", "VICYHRNDTGA");
1193 SequenceI[] seqs = new SequenceI[2];
1196 String[] result = h.getVisibleSequenceStrings(5, 10, seqs);
1197 assertEquals(2, result.length);
1198 assertEquals("WKQES", result[0]);
1199 assertEquals("RNDTG", result[1]);
1201 h.hideColumns(6, 8);
1202 result = h.getVisibleSequenceStrings(5, 10, seqs);
1203 assertEquals(2, result.length);
1204 assertEquals("WS", result[0]);
1205 assertEquals("RG", result[1]);
1207 SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
1208 ColumnSelection sel = new ColumnSelection();
1209 h.revealAllHiddenColumns(sel);
1210 h.hideColumns(1, 3);
1211 h.hideColumns(6, 11);
1213 h.getVisibleSequenceStrings(0, 5, new SequenceI[]
1217 @Test(groups = "Functional")
1218 public void testHideInsertionsFor()
1220 HiddenColumns h = new HiddenColumns();
1221 HiddenColumns h2 = new HiddenColumns();
1222 SequenceI seq1 = new Sequence("TEST1", "GAL---MFW-KQESPVICY--HRNDT");
1223 SequenceI seq2 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
1225 h.hideInsertionsFor(seq2);
1226 assertTrue(h.equals(h2));
1228 h.hideInsertionsFor(seq1);
1229 h2.hideColumns(3, 5);
1230 h2.hideColumns(9, 9);
1231 h2.hideColumns(19, 20);
1232 assertTrue(h.equals(h2));
1235 @Test(groups = "Functional")
1236 public void testHideMarkedBits()
1238 HiddenColumns h = new HiddenColumns();
1239 HiddenColumns h2 = new HiddenColumns();
1241 BitSet tohide = new BitSet(21);
1242 h.hideMarkedBits(tohide);
1243 assertTrue(h.equals(h2));
1245 // NB in hideMarkedBits, the last bit is not set to hidden
1249 h.hideMarkedBits(tohide);
1251 h2.hideColumns(3, 5);
1252 h2.hideColumns(9, 9);
1253 h2.hideColumns(19, 20);
1254 assertTrue(h.equals(h2));
1257 @Test(groups = "Functional")
1258 public void testMakeVisibleAnnotation()
1260 HiddenColumns h = new HiddenColumns();
1261 Annotation[] anns = new Annotation[] { null, null, new Annotation(1),
1262 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1263 new Annotation(5), new Annotation(6), new Annotation(7),
1264 new Annotation(8) };
1265 AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an",
1268 // without hidden cols, just truncates
1269 h.makeVisibleAnnotation(3, 5, ann);
1270 assertEquals(3, ann.annotations.length);
1271 assertEquals(2.0f, ann.annotations[0].value);
1272 assertEquals(3.0f, ann.annotations[1].value);
1273 assertNull(ann.annotations[2]);
1275 anns = new Annotation[] { null, null, new Annotation(1),
1276 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1277 new Annotation(5), new Annotation(6), new Annotation(7),
1278 new Annotation(8) };
1279 ann = new AlignmentAnnotation("an", "some an", anns);
1280 h.hideColumns(4, 7);
1281 h.makeVisibleAnnotation(1, 9, ann);
1282 assertEquals(5, ann.annotations.length);
1283 assertNull(ann.annotations[0]);
1284 assertEquals(1.0f, ann.annotations[1].value);
1285 assertEquals(2.0f, ann.annotations[2].value);
1286 assertEquals(5.0f, ann.annotations[3].value);
1287 assertEquals(6.0f, ann.annotations[4].value);
1289 anns = new Annotation[] { null, null, new Annotation(1),
1290 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1291 new Annotation(5), new Annotation(6), new Annotation(7),
1292 new Annotation(8) };
1293 ann = new AlignmentAnnotation("an", "some an", anns);
1294 h.hideColumns(1, 2);
1295 h.makeVisibleAnnotation(1, 9, ann);
1296 assertEquals(3, ann.annotations.length);
1297 assertEquals(2.0f, ann.annotations[0].value);
1298 assertEquals(5.0f, ann.annotations[1].value);
1299 assertEquals(6.0f, ann.annotations[2].value);
1302 @Test(groups = "Functional")
1303 public void testSubtractVisibleColumns()
1305 HiddenColumns h = new HiddenColumns();
1306 int result = h.subtractVisibleColumns(1, 10);
1307 assertEquals(9, result);
1309 h.hideColumns(7, 9);
1310 result = h.subtractVisibleColumns(4, 10);
1311 assertEquals(3, result);
1313 h.hideColumns(14, 15);
1314 result = h.subtractVisibleColumns(4, 10);
1315 assertEquals(3, result);
1317 result = h.subtractVisibleColumns(10, 17);
1318 assertEquals(2, result);
1320 result = h.subtractVisibleColumns(1, 7);
1321 assertEquals(5, result);
1323 result = h.subtractVisibleColumns(1, 8);
1324 assertEquals(5, result);
1326 result = h.subtractVisibleColumns(3, 15);
1327 assertEquals(10, result);
1329 ColumnSelection sel = new ColumnSelection();
1330 h.revealAllHiddenColumns(sel);
1331 h.hideColumns(0, 30);
1332 result = h.subtractVisibleColumns(31, 0);
1333 assertEquals(-31, result);
1336 @Test(groups = "Functional")
1337 public void testBoundedIterator()
1339 HiddenColumns h = new HiddenColumns();
1340 Iterator<int[]> it = h.getBoundedIterator(0, 10, false);
1342 // no hidden columns = nothing to iterate over
1343 assertFalse(it.hasNext());
1345 // [start,end] contains all hidden columns
1346 // all regions are returned
1347 h.hideColumns(3, 10);
1348 h.hideColumns(14, 16);
1349 it = h.getBoundedIterator(0, 20, false);
1350 assertTrue(it.hasNext());
1351 int[] next = it.next();
1352 assertEquals(3, next[0]);
1353 assertEquals(10, next[1]);
1355 assertEquals(14, next[0]);
1356 assertEquals(16, next[1]);
1357 assertFalse(it.hasNext());
1359 // [start,end] overlaps a region
1360 // 1 region returned
1361 it = h.getBoundedIterator(5, 7, false);
1362 assertTrue(it.hasNext());
1364 assertEquals(3, next[0]);
1365 assertEquals(10, next[1]);
1366 assertFalse(it.hasNext());
1368 // [start,end] fully contains 1 region and start of last
1369 // - 2 regions returned
1370 it = h.getBoundedIterator(3, 15, false);
1371 assertTrue(it.hasNext());
1373 assertEquals(3, next[0]);
1374 assertEquals(10, next[1]);
1376 assertEquals(14, next[0]);
1377 assertEquals(16, next[1]);
1378 assertFalse(it.hasNext());
1380 // [start,end] contains end of first region and whole of last region
1381 // - 2 regions returned
1382 it = h.getBoundedIterator(4, 20, false);
1383 assertTrue(it.hasNext());
1385 assertEquals(3, next[0]);
1386 assertEquals(10, next[1]);
1388 assertEquals(14, next[0]);
1389 assertEquals(16, next[1]);
1390 assertFalse(it.hasNext());
1393 @Test(groups = "Functional")
1394 public void testBoundedStartIterator()
1396 HiddenColumns h = new HiddenColumns();
1397 Iterator<Integer> it = h.getBoundedStartIterator(0, 10, false);
1399 // no hidden columns = nothing to iterate over
1400 assertFalse(it.hasNext());
1402 // [start,end] contains all hidden columns
1403 // all regions are returned
1404 h.hideColumns(3, 10);
1405 h.hideColumns(14, 16);
1406 it = h.getBoundedStartIterator(0, 20, false);
1407 assertTrue(it.hasNext());
1408 int next = it.next();
1409 assertEquals(3, next);
1411 assertEquals(6, next);
1412 assertFalse(it.hasNext());
1414 // [start,end] does not contain a start of a region
1415 // no regions to iterate over
1416 it = h.getBoundedStartIterator(4, 5, false);
1417 assertFalse(it.hasNext());
1419 // [start,end] fully contains 1 region and start of last
1420 // - 2 regions returned
1421 it = h.getBoundedStartIterator(3, 7, false);
1422 assertTrue(it.hasNext());
1424 assertEquals(3, next);
1426 assertEquals(6, next);
1427 assertFalse(it.hasNext());
1429 // [start,end] contains whole of last region
1430 // - 1 region returned
1431 it = h.getBoundedStartIterator(4, 20, false);
1432 assertTrue(it.hasNext());
1434 assertEquals(6, next);
1435 assertFalse(it.hasNext());