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.Random;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.Test;
40 public class HiddenColumnsTest
43 @BeforeClass(alwaysRun = true)
44 public void setUpJvOptionPane()
46 JvOptionPane.setInteractiveMode(false);
47 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51 * Test the method which counts the number of hidden columns
53 @Test(groups = { "Functional" })
54 public void testGetSize()
56 HiddenColumns hidden = new HiddenColumns();
57 assertEquals(0, hidden.getSize());
59 hidden.hideColumns(3, 5);
60 assertEquals(3, hidden.getSize());
62 hidden.hideColumns(8, 8);
63 assertEquals(4, hidden.getSize());
65 hidden.hideColumns(9, 14);
66 assertEquals(10, hidden.getSize());
68 ColumnSelection cs = new ColumnSelection();
69 hidden.revealAllHiddenColumns(cs);
70 assertEquals(0, hidden.getSize());
74 * Test the method that finds the visible column position of an alignment
75 * column, allowing for hidden columns.
77 @Test(groups = { "Functional" })
78 public void testFindColumnPosition()
80 HiddenColumns cs = new HiddenColumns();
81 assertEquals(5, cs.findColumnPosition(5));
83 // hiding column 6 makes no difference
85 assertEquals(5, cs.findColumnPosition(5));
87 // hiding column 4 moves column 5 to column 4
89 assertEquals(4, cs.findColumnPosition(5));
91 // hiding column 4 moves column 4 to position 3
92 assertEquals(3, cs.findColumnPosition(4));
94 // hiding columns 1 and 2 moves column 5 to column 2
96 assertEquals(2, cs.findColumnPosition(5));
98 // check with > 1 hidden column regions
99 // where some columns are in the hidden regions
100 HiddenColumns cs2 = new HiddenColumns();
101 cs2.hideColumns(5, 10);
102 cs2.hideColumns(20, 27);
103 cs2.hideColumns(40, 44);
105 // hiding columns 5-10 and 20-27 moves column 8 to column 4
106 assertEquals(4, cs2.findColumnPosition(8));
108 // and moves column 24 to 13
109 assertEquals(13, cs2.findColumnPosition(24));
111 // and moves column 28 to 14
112 assertEquals(14, cs2.findColumnPosition(28));
114 // and moves column 40 to 25
115 assertEquals(25, cs2.findColumnPosition(40));
117 // check when hidden columns start at 0 that the visible column
119 HiddenColumns cs3 = new HiddenColumns();
120 cs3.hideColumns(0, 4);
121 assertEquals(0, cs3.findColumnPosition(2));
126 * Test the method that finds the visible column position a given distance
127 * before another column
129 @Test(groups = { "Functional" })
130 public void testFindColumnNToLeft()
132 HiddenColumns cs = new HiddenColumns();
134 // test that without hidden columns, findColumnNToLeft returns
135 // position n to left of provided position
136 long pos = cs.subtractVisibleColumns(3, 10);
137 assertEquals(7, pos);
139 // 0 returns same position
140 pos = cs.subtractVisibleColumns(0, 10);
141 assertEquals(10, pos);
143 // overflow to left returns negative number
144 pos = cs.subtractVisibleColumns(3, 0);
145 assertEquals(-3, pos);
147 // test that with hidden columns to left of result column
148 // behaviour is the same as above
149 cs.hideColumns(1, 3);
151 // position n to left of provided position
152 pos = cs.subtractVisibleColumns(3, 10);
153 assertEquals(7, pos);
155 // 0 returns same position
156 pos = cs.subtractVisibleColumns(0, 10);
157 assertEquals(10, pos);
159 // test with one set of hidden columns between start and required position
160 cs.hideColumns(12, 15);
161 pos = cs.subtractVisibleColumns(8, 17);
162 assertEquals(5, pos);
164 // test with two sets of hidden columns between start and required position
165 cs.hideColumns(20, 21);
166 pos = cs.subtractVisibleColumns(8, 23);
167 assertEquals(9, pos);
169 // repeat last 2 tests with no hidden columns to left of required position
170 ColumnSelection colsel = new ColumnSelection();
171 cs.revealAllHiddenColumns(colsel);
173 // test with one set of hidden columns between start and required position
174 cs.hideColumns(12, 15);
175 pos = cs.subtractVisibleColumns(8, 17);
176 assertEquals(5, pos);
178 // test with two sets of hidden columns between start and required position
179 cs.hideColumns(20, 21);
180 pos = cs.subtractVisibleColumns(8, 23);
181 assertEquals(9, pos);
185 @Test(groups = { "Functional" })
186 public void testVisibleContigsIterator()
188 HiddenColumns cs = new HiddenColumns();
190 Iterator<int[]> visible = cs.getVisContigsIterator(3, 10);
191 int[] region = visible.next();
192 assertEquals("[3, 9]", Arrays.toString(region));
193 assertFalse(visible.hasNext());
195 cs.hideColumns(3, 6);
196 cs.hideColumns(8, 9);
197 cs.hideColumns(12, 12);
199 // Test both ends visible region
201 // start position is inclusive, end position exclusive
202 visible = cs.getVisContigsIterator(1, 13);
203 region = visible.next();
204 assertEquals("[1, 2]", Arrays.toString(region));
205 region = visible.next();
206 assertEquals("[7, 7]", Arrays.toString(region));
207 region = visible.next();
208 assertEquals("[10, 11]", Arrays.toString(region));
209 assertFalse(visible.hasNext());
211 // Test start hidden, end visible
212 visible = cs.getVisContigsIterator(4, 14);
213 region = visible.next();
214 assertEquals("[7, 7]", Arrays.toString(region));
215 region = visible.next();
216 assertEquals("[10, 11]", Arrays.toString(region));
217 region = visible.next();
218 assertEquals("[13, 13]", Arrays.toString(region));
219 assertFalse(visible.hasNext());
221 // Test start hidden, end hidden
222 visible = cs.getVisContigsIterator(3, 10);
223 region = visible.next();
224 assertEquals("[7, 7]", Arrays.toString(region));
225 assertFalse(visible.hasNext());
227 // Test start visible, end hidden
228 visible = cs.getVisContigsIterator(0, 13);
229 region = visible.next();
230 assertEquals("[0, 2]", Arrays.toString(region));
231 region = visible.next();
232 assertEquals("[7, 7]", Arrays.toString(region));
233 region = visible.next();
234 assertEquals("[10, 11]", Arrays.toString(region));
235 assertFalse(visible.hasNext());
238 visible = cs.getVisContigsIterator(4, 6);
239 assertFalse(visible.hasNext());
242 @Test(groups = { "Functional" })
243 public void testEquals()
245 HiddenColumns cs = new HiddenColumns();
246 cs.hideColumns(5, 9);
248 // a different set of hidden columns
249 HiddenColumns cs2 = new HiddenColumns();
251 // with no hidden columns
252 assertFalse(cs.equals(cs2));
253 assertFalse(cs2.equals(cs));
255 // with hidden columns added in a different order
256 cs2.hideColumns(6, 9);
257 cs2.hideColumns(5, 8);
259 assertTrue(cs.equals(cs2));
260 assertTrue(cs.equals(cs));
261 assertTrue(cs2.equals(cs));
262 assertTrue(cs2.equals(cs2));
265 @Test(groups = "Functional")
266 public void testCopyConstructor()
268 HiddenColumns cs = new HiddenColumns();
269 cs.hideColumns(10, 11);
270 cs.hideColumns(5, 7);
271 Iterator<int[]> regions = cs.iterator();
272 assertEquals("[5, 7]",
273 Arrays.toString(regions.next()));
275 HiddenColumns cs2 = new HiddenColumns(cs);
276 regions = cs2.iterator();
277 assertTrue(cs2.hasHiddenColumns());
278 assertEquals(2, cs2.getNumberOfRegions());
279 // hidden columns are held in column order
280 assertEquals("[5, 7]",
281 Arrays.toString(regions.next()));
282 assertEquals("[10, 11]",
283 Arrays.toString(regions.next()));
286 @Test(groups = "Functional")
287 public void testCopyConstructor2()
289 HiddenColumns cs = new HiddenColumns();
290 cs.hideColumns(10, 11);
291 cs.hideColumns(5, 7);
293 HiddenColumns cs2 = new HiddenColumns(cs, 3, 9, 1);
294 assertTrue(cs2.hasHiddenColumns());
295 Iterator<int[]> regions = cs2.iterator();
297 // only [5,7] returned, offset by 1
298 assertEquals("[4, 6]",
299 Arrays.toString(regions.next()));
300 assertEquals(3, cs2.getSize());
302 cs2 = new HiddenColumns(cs, 8, 15, 4);
303 regions = cs2.iterator();
304 assertTrue(cs2.hasHiddenColumns());
306 // only [10,11] returned, offset by 4
307 assertEquals("[6, 7]",
308 Arrays.toString(regions.next()));
309 assertEquals(2, cs2.getSize());
311 cs2 = new HiddenColumns(cs, 6, 10, 4);
312 assertFalse(cs2.hasHiddenColumns());
316 * Test the code used to locate the reference sequence ruler origin
318 @Test(groups = { "Functional" })
319 public void testLocateVisibleBoundsofSequence()
321 // create random alignment
322 AlignmentGenerator gen = new AlignmentGenerator(false);
323 AlignmentI al = gen.generate(50, 20, 123, 5, 5);
325 HiddenColumns cs = al.getHiddenColumns();
326 ColumnSelection colsel = new ColumnSelection();
328 SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
329 assertEquals(2, seq.findIndex(seq.getStart()));
333 Arrays.toString(new int[]
334 { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getStart()) - 1,
335 seq.findIndex(seq.getEnd()) - 1 }),
336 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
338 // hidden column on gap after end of sequence - should not affect bounds
339 colsel.hideSelectedColumns(13, al.getHiddenColumns());
341 Arrays.toString(new int[]
342 { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getStart()) - 1,
343 seq.findIndex(seq.getEnd()) - 1 }),
344 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
346 cs.revealAllHiddenColumns(colsel);
347 // hidden column on gap before beginning of sequence - should vis bounds by
349 colsel.hideSelectedColumns(0, al.getHiddenColumns());
351 Arrays.toString(new int[]
352 { seq.findIndex(seq.getStart()) - 2, seq.findIndex(seq.getStart()) - 1,
353 seq.findIndex(seq.getEnd()) - 1 }),
354 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
356 cs.revealAllHiddenColumns(colsel);
357 // hide columns around most of sequence - leave one residue remaining
358 cs.hideColumns(1, 3);
359 cs.hideColumns(6, 11);
361 cs.getVisibleSequenceStrings(0, 5, new SequenceI[]
367 { 1, seq.findIndex(seq.getStart()) - 1,
368 seq.findIndex(seq.getEnd()) - 1 }),
369 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
370 cs.revealAllHiddenColumns(colsel);
372 // hide whole sequence - should just get location of hidden region
373 // containing sequence
374 cs.hideColumns(1, 11);
378 { 0, seq.findIndex(seq.getStart()) - 1,
379 seq.findIndex(seq.getEnd()) - 1 }),
380 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
382 cs.revealAllHiddenColumns(colsel);
383 cs.hideColumns(0, 15);
386 { 0, seq.findIndex(seq.getStart()) - 1,
387 seq.findIndex(seq.getEnd()) - 1 }),
388 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
390 SequenceI seq2 = new Sequence("RefSeq2", "-------A-SD-ASD--E---");
392 cs.revealAllHiddenColumns(colsel);
393 cs.hideColumns(7, 17);
397 { 0, seq2.findIndex(seq2.getStart()) - 1,
398 seq2.findIndex(seq2.getEnd()) - 1 }),
399 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
401 cs.revealAllHiddenColumns(colsel);
402 cs.hideColumns(3, 17);
406 { 0, seq2.findIndex(seq2.getStart()) - 1,
407 seq2.findIndex(seq2.getEnd()) - 1 }),
408 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
410 cs.revealAllHiddenColumns(colsel);
411 cs.hideColumns(3, 19);
415 { 0, seq2.findIndex(seq2.getStart()) - 1,
416 seq2.findIndex(seq2.getEnd()) - 1 }),
417 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
419 cs.revealAllHiddenColumns(colsel);
420 cs.hideColumns(0, 0);
421 int[] test = cs.locateVisibleBoundsOfSequence(seq);
422 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
423 Arrays.toString(test));
425 cs.revealAllHiddenColumns(colsel);
426 cs.hideColumns(0, 1);
427 test = cs.locateVisibleBoundsOfSequence(seq);
428 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
429 Arrays.toString(test));
431 cs.revealAllHiddenColumns(colsel);
432 cs.hideColumns(0, 2);
433 test = cs.locateVisibleBoundsOfSequence(seq);
434 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
435 Arrays.toString(test));
437 cs.revealAllHiddenColumns(colsel);
438 cs.hideColumns(1, 1);
439 test = cs.locateVisibleBoundsOfSequence(seq);
440 assertEquals(Arrays.toString(new int[] { 2, 1, 11 }),
441 Arrays.toString(test));
443 cs.revealAllHiddenColumns(colsel);
444 cs.hideColumns(1, 2);
445 test = cs.locateVisibleBoundsOfSequence(seq);
446 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
447 Arrays.toString(test));
449 cs.revealAllHiddenColumns(colsel);
450 cs.hideColumns(1, 3);
451 test = cs.locateVisibleBoundsOfSequence(seq);
452 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
453 Arrays.toString(test));
455 cs.revealAllHiddenColumns(colsel);
456 cs.hideColumns(0, 2);
457 cs.hideColumns(5, 6);
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(0, 2);
464 cs.hideColumns(5, 6);
465 cs.hideColumns(9, 10);
466 test = cs.locateVisibleBoundsOfSequence(seq);
467 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
468 Arrays.toString(test));
470 cs.revealAllHiddenColumns(colsel);
471 cs.hideColumns(0, 2);
472 cs.hideColumns(7, 11);
473 test = cs.locateVisibleBoundsOfSequence(seq);
474 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
475 Arrays.toString(test));
477 cs.revealAllHiddenColumns(colsel);
478 cs.hideColumns(2, 4);
479 cs.hideColumns(7, 11);
480 test = cs.locateVisibleBoundsOfSequence(seq);
481 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
482 Arrays.toString(test));
484 cs.revealAllHiddenColumns(colsel);
485 cs.hideColumns(2, 4);
486 cs.hideColumns(7, 12);
487 test = cs.locateVisibleBoundsOfSequence(seq);
488 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
489 Arrays.toString(test));
491 cs.revealAllHiddenColumns(colsel);
492 cs.hideColumns(1, 11);
493 test = cs.locateVisibleBoundsOfSequence(seq);
494 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
495 Arrays.toString(test));
497 cs.revealAllHiddenColumns(colsel);
498 cs.hideColumns(0, 12);
499 test = cs.locateVisibleBoundsOfSequence(seq);
500 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
501 Arrays.toString(test));
503 cs.revealAllHiddenColumns(colsel);
504 cs.hideColumns(0, 4);
505 cs.hideColumns(6, 12);
506 test = cs.locateVisibleBoundsOfSequence(seq);
507 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
508 Arrays.toString(test));
510 cs.revealAllHiddenColumns(colsel);
511 cs.hideColumns(0, 1);
512 cs.hideColumns(3, 12);
513 test = cs.locateVisibleBoundsOfSequence(seq);
514 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
515 Arrays.toString(test));
517 // These tests cover different behaviour to original
518 // locateVisibleBoundsOfSequence
519 // Previously first values of each were 3,9 and 6 respectively.
520 cs.revealAllHiddenColumns(colsel);
521 cs.hideColumns(3, 14);
522 cs.hideColumns(17, 19);
526 { 3, seq2.findIndex(seq2.getStart()) - 1,
527 seq2.findIndex(seq2.getEnd()) - 1 }),
528 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
530 cs.revealAllHiddenColumns(colsel);
531 cs.hideColumns(3, 7);
532 cs.hideColumns(9, 14);
533 cs.hideColumns(17, 19);
537 { 9, seq2.findIndex(seq2.getStart()) - 1,
538 seq2.findIndex(seq2.getEnd()) - 1 }),
539 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
541 cs.revealAllHiddenColumns(colsel);
542 cs.hideColumns(0, 1);
543 cs.hideColumns(3, 4);
544 cs.hideColumns(6, 8);
545 cs.hideColumns(10, 12);
546 test = cs.locateVisibleBoundsOfSequence(seq);
547 assertEquals(Arrays.toString(new int[] { 6, 1, 11 }),
548 Arrays.toString(test));
552 @Test(groups = { "Functional" })
553 public void testLocateVisibleBoundsPathologicals()
555 // test some pathological cases we missed
556 AlignmentI al = new Alignment(
558 { new Sequence("refseqGaptest", "KTDVTI----------NFI-----G----L") });
559 HiddenColumns cs = new HiddenColumns();
560 cs.hideInsertionsFor(al.getSequenceAt(0));
562 + al.getSequenceAt(0).getCharAt(cs.adjustForHiddenColumns(9)));
566 @Test(groups = { "Functional" })
567 public void testHideColumns()
569 // create random alignment
570 AlignmentGenerator gen = new AlignmentGenerator(false);
571 AlignmentI al = gen.generate(50, 20, 123, 5, 5);
573 ColumnSelection colsel = new ColumnSelection();
574 HiddenColumns cs = al.getHiddenColumns();
575 colsel.hideSelectedColumns(5, al.getHiddenColumns());
576 Iterator<int[]> regions = cs.iterator();
577 assertEquals(1, cs.getNumberOfRegions());
578 assertEquals("[5, 5]", Arrays.toString(regions.next()));
580 colsel.hideSelectedColumns(3, al.getHiddenColumns());
581 regions = cs.iterator();
582 assertEquals(2, cs.getNumberOfRegions());
583 // two hidden ranges, in order:
584 assertEquals("[3, 3]", Arrays.toString(regions.next()));
585 assertEquals("[5, 5]", Arrays.toString(regions.next()));
587 // hiding column 4 expands [3, 3] to [3, 4]
588 // and merges to [5, 5] to make [3, 5]
589 colsel.hideSelectedColumns(4, al.getHiddenColumns());
590 regions = cs.iterator();
591 assertEquals(1, cs.getNumberOfRegions());
592 assertEquals("[3, 5]", Arrays.toString(regions.next()));
594 // clear hidden columns (note they are added to selected)
595 cs.revealAllHiddenColumns(colsel);
596 // it is now actually null but getter returns an empty list
597 assertEquals(0, cs.getNumberOfRegions());
599 cs.hideColumns(3, 6);
600 regions = cs.iterator();
601 int[] firstHiddenRange = regions.next();
602 assertEquals("[3, 6]", Arrays.toString(firstHiddenRange));
604 // adding a subrange of already hidden should do nothing
605 cs.hideColumns(4, 5);
606 regions = cs.iterator();
607 assertEquals(1, cs.getNumberOfRegions());
608 assertEquals("[3, 6]",
609 Arrays.toString(regions.next()));
610 cs.hideColumns(3, 5);
611 regions = cs.iterator();
612 assertEquals(1, cs.getNumberOfRegions());
613 assertEquals("[3, 6]",
614 Arrays.toString(regions.next()));
615 cs.hideColumns(4, 6);
616 regions = cs.iterator();
617 assertEquals(1, cs.getNumberOfRegions());
618 assertEquals("[3, 6]",
619 Arrays.toString(regions.next()));
620 cs.hideColumns(3, 6);
621 regions = cs.iterator();
622 assertEquals(1, cs.getNumberOfRegions());
623 assertEquals("[3, 6]",
624 Arrays.toString(regions.next()));
626 cs.revealAllHiddenColumns(colsel);
627 cs.hideColumns(2, 4);
628 regions = cs.iterator();
629 assertEquals(1, cs.getNumberOfRegions());
630 assertEquals("[2, 4]", Arrays.toString(regions.next()));
632 // extend contiguous with 2 positions overlap
633 cs.hideColumns(3, 5);
634 regions = cs.iterator();
635 assertEquals(1, cs.getNumberOfRegions());
636 assertEquals("[2, 5]", Arrays.toString(regions.next()));
638 // extend contiguous with 1 position overlap
639 cs.hideColumns(5, 6);
640 regions = cs.iterator();
641 assertEquals(1, cs.getNumberOfRegions());
642 assertEquals("[2, 6]", Arrays.toString(regions.next()));
644 // extend contiguous with overlap both ends:
645 cs.hideColumns(1, 7);
646 regions = cs.iterator();
647 assertEquals(1, cs.getNumberOfRegions());
648 assertEquals("[1, 7]", Arrays.toString(regions.next()));
652 * Test the method that reveals a range of hidden columns given the start
653 * column of the range
655 @Test(groups = { "Functional" })
656 public void testRevealHiddenColumns()
658 ColumnSelection colsel = new ColumnSelection();
659 HiddenColumns cs = new HiddenColumns();
660 cs.hideColumns(5, 8);
661 colsel.addElement(10);
662 cs.revealHiddenColumns(5, colsel);
664 // hiddenColumns now empty
665 assertEquals(0, cs.getSize());
667 // revealed columns are marked as selected (added to selection):
668 assertEquals("[10, 5, 6, 7, 8]", colsel.getSelected().toString());
670 // calling with a column other than the range start does nothing:
671 colsel = new ColumnSelection();
672 cs = new HiddenColumns();
673 cs.hideColumns(5, 8);
675 int prevSize = cs.getSize();
676 cs.revealHiddenColumns(6, colsel);
677 assertEquals(prevSize, cs.getSize());
678 assertTrue(colsel.getSelected().isEmpty());
681 @Test(groups = { "Functional" })
682 public void testRevealAllHiddenColumns()
684 HiddenColumns hidden = new HiddenColumns();
685 ColumnSelection colsel = new ColumnSelection();
686 hidden.hideColumns(5, 8);
687 hidden.hideColumns(2, 3);
688 colsel.addElement(11);
689 colsel.addElement(1);
690 hidden.revealAllHiddenColumns(colsel);
693 * revealing hidden columns adds them (in order) to the (unordered)
697 // hiddenColumns now empty
698 assertEquals(0, hidden.getSize());
700 assertEquals("[11, 1, 2, 3, 5, 6, 7, 8]",
701 colsel.getSelected().toString());
704 @Test(groups = { "Functional" })
705 public void testIsVisible()
707 HiddenColumns cs = new HiddenColumns();
708 cs.hideColumns(2, 4);
709 cs.hideColumns(6, 7);
710 assertTrue(cs.isVisible(0));
711 assertTrue(cs.isVisible(-99));
712 assertTrue(cs.isVisible(1));
713 assertFalse(cs.isVisible(2));
714 assertFalse(cs.isVisible(3));
715 assertFalse(cs.isVisible(4));
716 assertTrue(cs.isVisible(5));
717 assertFalse(cs.isVisible(6));
718 assertFalse(cs.isVisible(7));
722 * Test for the case when a hidden range encloses more one already hidden
725 @Test(groups = { "Functional" })
726 public void testHideColumns_subsumingHidden()
729 * JAL-2370 bug scenario:
730 * two hidden ranges subsumed by a third
732 HiddenColumns cs = new HiddenColumns();
733 cs.hideColumns(49, 59);
734 cs.hideColumns(69, 79);
735 Iterator<int[]> regions = cs.iterator();
736 assertEquals(2, cs.getNumberOfRegions());
737 assertEquals("[49, 59]", Arrays.toString(regions.next()));
738 assertEquals("[69, 79]", Arrays.toString(regions.next()));
740 cs.hideColumns(48, 80);
741 regions = cs.iterator();
742 assertEquals(1, cs.getNumberOfRegions());
743 assertEquals("[48, 80]", Arrays.toString(regions.next()));
746 * another...joining hidden ranges
748 cs = new HiddenColumns();
749 cs.hideColumns(10, 20);
750 cs.hideColumns(30, 40);
751 cs.hideColumns(50, 60);
752 // hiding 21-49 should merge to one range
753 cs.hideColumns(21, 49);
754 regions = cs.iterator();
755 assertEquals(1, cs.getNumberOfRegions());
756 assertEquals("[10, 60]", Arrays.toString(regions.next()));
759 * another...left overlap, subsumption, right overlap,
760 * no overlap of existing hidden ranges
762 cs = new HiddenColumns();
763 cs.hideColumns(10, 20);
764 cs.hideColumns(10, 20);
765 cs.hideColumns(30, 35);
766 cs.hideColumns(40, 50);
767 cs.hideColumns(60, 70);
769 cs.hideColumns(15, 45);
770 regions = cs.iterator();
771 assertEquals(2, cs.getNumberOfRegions());
772 assertEquals("[10, 50]", Arrays.toString(regions.next()));
773 assertEquals("[60, 70]", Arrays.toString(regions.next()));
776 @Test(groups = { "Functional" })
777 public void testHideBitset()
781 BitSet one = new BitSet();
785 cs = new HiddenColumns();
786 cs.hideMarkedBits(one);
787 assertEquals(1, cs.getNumberOfRegions());
790 cs = new HiddenColumns();
791 cs.hideMarkedBits(one);
792 assertEquals(1, cs.getNumberOfRegions());
795 cs = new HiddenColumns();
796 cs.hideMarkedBits(one);
797 assertEquals(1, cs.getNumberOfRegions());
801 cs = new HiddenColumns();
802 cs.hideMarkedBits(one);
803 assertEquals(2, cs.getNumberOfRegions());
805 assertEquals(0, cs.adjustForHiddenColumns(0));
806 assertEquals(2, cs.adjustForHiddenColumns(1));
807 assertEquals(4, cs.adjustForHiddenColumns(2));
811 cs = new HiddenColumns();
812 cs.hideMarkedBits(one);
814 assertEquals(1, cs.getNumberOfRegions());
816 assertEquals(0, cs.adjustForHiddenColumns(0));
817 assertEquals(1, cs.adjustForHiddenColumns(1));
818 assertEquals(2, cs.adjustForHiddenColumns(2));
819 assertEquals(4, cs.adjustForHiddenColumns(3));
822 @Test(groups = { "Functional" })
823 public void testMarkHiddenRegions()
825 BitSet toMark, fromMark;
826 long seed = -3241532;
827 Random number = new Random(seed);
828 for (int n = 0; n < 1000; n++)
830 // create a random bitfield
833 { number.nextLong(), number.nextLong(), number.nextLong() });
834 toMark.set(n * number.nextInt(10), n * (25 + number.nextInt(25)));
835 HiddenColumns hc = new HiddenColumns();
836 hc.hideMarkedBits(toMark);
838 // see if we can recover bitfield
839 hc.markHiddenRegions(fromMark = new BitSet());
840 assertEquals(toMark, fromMark);
844 @Test(groups = { "Functional" })
845 public void testRegionsToString()
847 HiddenColumns hc = new HiddenColumns();
849 String result = hc.regionsToString(",", "--");
850 assertEquals("", result);
852 hc.hideColumns(3, 7);
853 hc.hideColumns(10, 10);
854 hc.hideColumns(14, 15);
856 result = hc.regionsToString(",", "--");
857 assertEquals("3--7,10--10,14--15", result);
860 @Test(groups = "Functional")
861 public void testGetVisibleStartAndEndIndexTest()
863 Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
864 AlignmentI align = new Alignment(new SequenceI[] { seq });
865 HiddenColumns hc = new HiddenColumns();
867 int[] startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
868 assertEquals(0, startEnd[0]);
869 assertEquals(25, startEnd[1]);
871 hc.hideColumns(0, 0);
872 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
873 assertEquals(1, startEnd[0]);
874 assertEquals(25, startEnd[1]);
876 hc.hideColumns(6, 9);
877 hc.hideColumns(11, 12);
878 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
879 assertEquals(1, startEnd[0]);
880 assertEquals(25, startEnd[1]);
882 hc.hideColumns(24, 25);
883 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
884 System.out.println(startEnd[0] + " : " + startEnd[1]);
885 assertEquals(1, startEnd[0]);
886 assertEquals(23, startEnd[1]);
889 @Test(groups = "Functional")
890 public void testGetRegionWithEdgeAtRes()
892 HiddenColumns hc = new HiddenColumns();
894 int[] result = hc.getRegionWithEdgeAtRes(5);
897 hc.hideColumns(3, 7);
898 hc.hideColumns(10, 10);
899 hc.hideColumns(14, 15);
901 result = hc.getRegionWithEdgeAtRes(2);
902 assertEquals(3, result[0]);
903 assertEquals(7, result[1]);
905 result = hc.getRegionWithEdgeAtRes(5);
906 assertEquals(10, result[0]);
907 assertEquals(10, result[1]);
909 result = hc.getRegionWithEdgeAtRes(6);
912 result = hc.getRegionWithEdgeAtRes(0);
915 result = hc.getRegionWithEdgeAtRes(7);
916 assertEquals(14, result[0]);
917 assertEquals(15, result[1]);
919 result = hc.getRegionWithEdgeAtRes(8);
920 assertEquals(14, result[0]);
921 assertEquals(15, result[1]);
924 @Test(groups = "Functional")
925 public void testPropagateInsertions()
927 // create an alignment with no gaps - this will be the profile seq and other
929 AlignmentGenerator gen = new AlignmentGenerator(false);
930 AlignmentI al = gen.generate(25, 10, 1234, 0, 0);
932 // get the profileseq
933 SequenceI profileseq = al.getSequenceAt(0);
934 SequenceI gappedseq = new Sequence(profileseq);
935 gappedseq.insertCharAt(5, al.getGapCharacter());
936 gappedseq.insertCharAt(6, al.getGapCharacter());
937 gappedseq.insertCharAt(7, al.getGapCharacter());
938 gappedseq.insertCharAt(8, al.getGapCharacter());
940 // create an alignment view with the gapped sequence
941 SequenceI[] seqs = new SequenceI[1];
943 AlignmentI newal = new Alignment(seqs);
944 HiddenColumns hidden = new HiddenColumns();
945 hidden.hideColumns(15, 17);
947 AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
950 // confirm that original contigs are as expected
951 Iterator<int[]> visible = hidden.getVisContigsIterator(0, 25);
952 int[] region = visible.next();
953 assertEquals("[0, 14]", Arrays.toString(region));
954 region = visible.next();
955 assertEquals("[18, 24]", Arrays.toString(region));
957 // propagate insertions
958 HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
961 // confirm that the contigs have changed to account for the gaps
962 visible = result.getVisContigsIterator(0, 25);
963 region = visible.next();
964 assertEquals("[0, 10]", Arrays.toString(region));
965 region = visible.next();
966 assertEquals("[14, 24]", Arrays.toString(region));
968 // confirm the alignment has been changed so that the other sequences have
969 // gaps inserted where the columns are hidden
970 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[10]));
971 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[11]));
972 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[12]));
973 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[13]));
974 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[14]));
978 @Test(groups = "Functional")
979 public void testPropagateInsertionsOverlap()
981 // test propagateInsertions where gaps and hiddenColumns overlap
983 // create an alignment with no gaps - this will be the profile seq and other
985 AlignmentGenerator gen = new AlignmentGenerator(false);
986 AlignmentI al = gen.generate(20, 10, 1234, 0, 0);
988 // get the profileseq
989 SequenceI profileseq = al.getSequenceAt(0);
990 SequenceI gappedseq = new Sequence(profileseq);
991 gappedseq.insertCharAt(5, al.getGapCharacter());
992 gappedseq.insertCharAt(6, al.getGapCharacter());
993 gappedseq.insertCharAt(7, al.getGapCharacter());
994 gappedseq.insertCharAt(8, al.getGapCharacter());
996 // create an alignment view with the gapped sequence
997 SequenceI[] seqs = new SequenceI[1];
999 AlignmentI newal = new Alignment(seqs);
1001 // hide columns so that some overlap with the gaps
1002 HiddenColumns hidden = new HiddenColumns();
1003 hidden.hideColumns(7, 10);
1005 AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
1008 // confirm that original contigs are as expected
1009 Iterator<int[]> visible = hidden.getVisContigsIterator(0, 20);
1010 int[] region = visible.next();
1011 assertEquals("[0, 6]", Arrays.toString(region));
1012 region = visible.next();
1013 assertEquals("[11, 19]", Arrays.toString(region));
1014 assertFalse(visible.hasNext());
1016 // propagate insertions
1017 HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
1020 // confirm that the contigs have changed to account for the gaps
1021 visible = result.getVisContigsIterator(0, 20);
1022 region = visible.next();
1023 assertEquals("[0, 4]", Arrays.toString(region));
1024 region = visible.next();
1025 assertEquals("[7, 19]", Arrays.toString(region));
1026 assertFalse(visible.hasNext());
1028 // confirm the alignment has been changed so that the other sequences have
1029 // gaps inserted where the columns are hidden
1030 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[4]));
1031 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[5]));
1032 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[6]));
1033 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[7]));
1036 @Test(groups = "Functional")
1037 public void testHasHiddenColumns()
1039 HiddenColumns h = new HiddenColumns();
1041 // new HiddenColumns2 has no hidden cols
1042 assertFalse(h.hasHiddenColumns());
1044 // some columns hidden, returns true
1045 h.hideColumns(5, 10);
1046 assertTrue(h.hasHiddenColumns());
1048 // reveal columns, no hidden cols again
1049 ColumnSelection sel = new ColumnSelection();
1050 h.revealAllHiddenColumns(sel);
1051 assertFalse(h.hasHiddenColumns());
1054 @Test(groups = "Functional")
1055 public void testHasManyHiddenColumns()
1057 HiddenColumns h = new HiddenColumns();
1059 // new HiddenColumns2 has no hidden cols
1060 assertFalse(h.hasManyHiddenColumns());
1062 // one set of columns hidden, returns false
1063 h.hideColumns(5, 10);
1064 assertFalse(h.hasManyHiddenColumns());
1066 // two sets hidden, returns true
1067 h.hideColumns(15, 17);
1068 assertTrue(h.hasManyHiddenColumns());
1070 // back to one block, asserts false
1071 h.hideColumns(11, 14);
1072 assertFalse(h.hasManyHiddenColumns());
1075 @Test(groups = "Functional")
1076 public void testAdjustForHiddenColumns()
1078 HiddenColumns h = new HiddenColumns();
1079 // returns input value when there are no hidden columns
1080 assertEquals(10, h.adjustForHiddenColumns(10));
1082 h.hideColumns(20, 30);
1083 assertEquals(10, h.adjustForHiddenColumns(10));
1084 assertEquals(20 + 11, h.adjustForHiddenColumns(20));
1085 assertEquals(35 + 11, h.adjustForHiddenColumns(35));
1087 h.hideColumns(5, 7);
1088 assertEquals(10 + 3, h.adjustForHiddenColumns(10));
1089 assertEquals(20 + 14, h.adjustForHiddenColumns(20));
1090 assertEquals(35 + 14, h.adjustForHiddenColumns(35));
1092 ColumnSelection sel = new ColumnSelection();
1093 h.revealAllHiddenColumns(sel);
1094 h.hideColumns(0, 1);
1095 assertEquals(4, h.adjustForHiddenColumns(2));
1098 @Test(groups = "Functional")
1099 public void testGetHiddenBoundaryLeft()
1101 HiddenColumns h = new HiddenColumns();
1103 // returns same value if no hidden cols
1104 assertEquals(3, h.getHiddenBoundaryLeft(3));
1106 h.hideColumns(5, 10);
1107 assertEquals(10, h.getHiddenBoundaryLeft(15));
1108 assertEquals(3, h.getHiddenBoundaryLeft(3));
1109 assertEquals(7, h.getHiddenBoundaryLeft(7));
1111 h.hideColumns(15, 20);
1112 assertEquals(10, h.getHiddenBoundaryLeft(15));
1113 assertEquals(20, h.getHiddenBoundaryLeft(21));
1116 @Test(groups = "Functional")
1117 public void testGetHiddenBoundaryRight()
1119 HiddenColumns h = new HiddenColumns();
1121 // returns same value if no hidden cols
1122 assertEquals(3, h.getHiddenBoundaryRight(3));
1124 h.hideColumns(5, 10);
1125 assertEquals(5, h.getHiddenBoundaryRight(3));
1126 assertEquals(15, h.getHiddenBoundaryRight(15));
1127 assertEquals(7, h.getHiddenBoundaryRight(7));
1129 h.hideColumns(15, 20);
1130 assertEquals(15, h.getHiddenBoundaryRight(7));
1131 assertEquals(15, h.getHiddenBoundaryRight(14));
1134 @Test(groups = "Functional")
1135 public void testIterator()
1137 HiddenColumns h = new HiddenColumns();
1138 Iterator<int[]> result = h.iterator();
1139 assertFalse(result.hasNext());
1141 h.hideColumns(5, 10);
1142 result = h.iterator();
1143 int[] next = result.next();
1144 assertEquals(5, next[0]);
1145 assertEquals(10, next[1]);
1146 assertFalse(result.hasNext());
1148 h.hideColumns(22, 23);
1149 result = h.iterator();
1150 next = result.next();
1151 assertEquals(5, next[0]);
1152 assertEquals(10, next[1]);
1153 next = result.next();
1154 assertEquals(22, next[0]);
1155 assertEquals(23, next[1]);
1156 assertFalse(result.hasNext());
1158 // test for only one hidden region at start of alignment
1159 ColumnSelection sel = new ColumnSelection();
1160 h.revealAllHiddenColumns(sel);
1161 h.hideColumns(0, 1);
1162 result = h.iterator();
1163 next = result.next();
1164 assertEquals(0, next[0]);
1165 assertEquals(1, next[1]);
1166 assertFalse(result.hasNext());
1169 @Test(groups = "Functional")
1170 public void testGetVisibleSequenceStrings()
1172 HiddenColumns h = new HiddenColumns();
1173 SequenceI seq1 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
1174 SequenceI seq2 = new Sequence("TEST2", "VICYHRNDTGA");
1175 SequenceI[] seqs = new SequenceI[2];
1178 String[] result = h.getVisibleSequenceStrings(5, 10, seqs);
1179 assertEquals(2, result.length);
1180 assertEquals("WKQES", result[0]);
1181 assertEquals("RNDTG", result[1]);
1183 h.hideColumns(6, 8);
1184 result = h.getVisibleSequenceStrings(5, 10, seqs);
1185 assertEquals(2, result.length);
1186 assertEquals("WS", result[0]);
1187 assertEquals("RG", result[1]);
1189 SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
1190 ColumnSelection sel = new ColumnSelection();
1191 h.revealAllHiddenColumns(sel);
1192 h.hideColumns(1, 3);
1193 h.hideColumns(6, 11);
1195 h.getVisibleSequenceStrings(0, 5, new SequenceI[]
1199 @Test(groups = "Functional")
1200 public void testHideInsertionsFor()
1202 HiddenColumns h = new HiddenColumns();
1203 HiddenColumns h2 = new HiddenColumns();
1204 SequenceI seq1 = new Sequence("TEST1", "GAL---MFW-KQESPVICY--HRNDT");
1205 SequenceI seq2 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
1207 h.hideInsertionsFor(seq2);
1208 assertTrue(h.equals(h2));
1210 h.hideInsertionsFor(seq1);
1211 h2.hideColumns(3, 5);
1212 h2.hideColumns(9, 9);
1213 h2.hideColumns(19, 20);
1214 assertTrue(h.equals(h2));
1217 @Test(groups = "Functional")
1218 public void testHideMarkedBits()
1220 HiddenColumns h = new HiddenColumns();
1221 HiddenColumns h2 = new HiddenColumns();
1223 BitSet tohide = new BitSet(21);
1224 h.hideMarkedBits(tohide);
1225 assertTrue(h.equals(h2));
1227 // NB in hideMarkedBits, the last bit is not set to hidden
1231 h.hideMarkedBits(tohide);
1233 h2.hideColumns(3, 5);
1234 h2.hideColumns(9, 9);
1235 h2.hideColumns(19, 20);
1236 assertTrue(h.equals(h2));
1239 @Test(groups = "Functional")
1240 public void testMakeVisibleAnnotation()
1242 HiddenColumns h = new HiddenColumns();
1243 Annotation[] anns = new Annotation[] { null, null, new Annotation(1),
1244 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1245 new Annotation(5), new Annotation(6), new Annotation(7),
1246 new Annotation(8) };
1247 AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an",
1250 // without hidden cols, just truncates
1251 h.makeVisibleAnnotation(3, 5, ann);
1252 assertEquals(3, ann.annotations.length);
1253 assertEquals(2.0f, ann.annotations[0].value);
1254 assertEquals(3.0f, ann.annotations[1].value);
1255 assertNull(ann.annotations[2]);
1257 anns = new Annotation[] { null, null, new Annotation(1),
1258 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1259 new Annotation(5), new Annotation(6), new Annotation(7),
1260 new Annotation(8) };
1261 ann = new AlignmentAnnotation("an", "some an", anns);
1262 h.hideColumns(4, 7);
1263 h.makeVisibleAnnotation(1, 9, ann);
1264 assertEquals(5, ann.annotations.length);
1265 assertNull(ann.annotations[0]);
1266 assertEquals(1.0f, ann.annotations[1].value);
1267 assertEquals(2.0f, ann.annotations[2].value);
1268 assertEquals(5.0f, ann.annotations[3].value);
1269 assertEquals(6.0f, ann.annotations[4].value);
1271 anns = new Annotation[] { null, null, new Annotation(1),
1272 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1273 new Annotation(5), new Annotation(6), new Annotation(7),
1274 new Annotation(8) };
1275 ann = new AlignmentAnnotation("an", "some an", anns);
1276 h.hideColumns(1, 2);
1277 h.makeVisibleAnnotation(1, 9, ann);
1278 assertEquals(3, ann.annotations.length);
1279 assertEquals(2.0f, ann.annotations[0].value);
1280 assertEquals(5.0f, ann.annotations[1].value);
1281 assertEquals(6.0f, ann.annotations[2].value);
1284 @Test(groups = "Functional")
1285 public void testSubtractVisibleColumns()
1287 HiddenColumns h = new HiddenColumns();
1288 int result = h.subtractVisibleColumns(1, 10);
1289 assertEquals(9, result);
1291 h.hideColumns(7, 9);
1292 result = h.subtractVisibleColumns(4, 10);
1293 assertEquals(3, result);
1295 h.hideColumns(14, 15);
1296 result = h.subtractVisibleColumns(4, 10);
1297 assertEquals(3, result);
1299 result = h.subtractVisibleColumns(10, 17);
1300 assertEquals(2, result);
1302 result = h.subtractVisibleColumns(1, 7);
1303 assertEquals(5, result);
1305 result = h.subtractVisibleColumns(1, 8);
1306 assertEquals(5, result);
1308 result = h.subtractVisibleColumns(3, 15);
1309 assertEquals(10, result);
1311 ColumnSelection sel = new ColumnSelection();
1312 h.revealAllHiddenColumns(sel);
1313 h.hideColumns(0, 30);
1314 result = h.subtractVisibleColumns(31, 0);
1315 assertEquals(-31, result);
1318 @Test(groups = "Functional")
1319 public void testBoundedIterator()
1321 HiddenColumns h = new HiddenColumns();
1322 Iterator<int[]> it = h.getBoundedIterator(0, 10);
1324 // no hidden columns = nothing to iterate over
1325 assertFalse(it.hasNext());
1327 // [start,end] contains all hidden columns
1328 // all regions are returned
1329 h.hideColumns(3, 10);
1330 h.hideColumns(14, 16);
1331 it = h.getBoundedIterator(0, 20);
1332 assertTrue(it.hasNext());
1333 int[] next = it.next();
1334 assertEquals(3, next[0]);
1335 assertEquals(10, next[1]);
1337 assertEquals(14, next[0]);
1338 assertEquals(16, next[1]);
1339 assertFalse(it.hasNext());
1341 // [start,end] overlaps a region
1342 // 1 region returned
1343 it = h.getBoundedIterator(5, 7);
1344 assertTrue(it.hasNext());
1346 assertEquals(3, next[0]);
1347 assertEquals(10, next[1]);
1348 assertFalse(it.hasNext());
1350 // [start,end] fully contains 1 region and start of last
1351 // - 2 regions returned
1352 it = h.getBoundedIterator(3, 15);
1353 assertTrue(it.hasNext());
1355 assertEquals(3, next[0]);
1356 assertEquals(10, next[1]);
1358 assertEquals(14, next[0]);
1359 assertEquals(16, next[1]);
1360 assertFalse(it.hasNext());
1362 // [start,end] contains end of first region and whole of last region
1363 // - 2 regions returned
1364 it = h.getBoundedIterator(4, 20);
1365 assertTrue(it.hasNext());
1367 assertEquals(3, next[0]);
1368 assertEquals(10, next[1]);
1370 assertEquals(14, next[0]);
1371 assertEquals(16, next[1]);
1372 assertFalse(it.hasNext());
1375 @Test(groups = "Functional")
1376 public void testBoundedStartIterator()
1378 HiddenColumns h = new HiddenColumns();
1379 Iterator<Integer> it = h.getBoundedStartIterator(0, 10);
1381 // no hidden columns = nothing to iterate over
1382 assertFalse(it.hasNext());
1384 // [start,end] contains all hidden columns
1385 // all regions are returned
1386 h.hideColumns(3, 10);
1387 h.hideColumns(14, 16);
1388 it = h.getBoundedStartIterator(0, 20);
1389 assertTrue(it.hasNext());
1390 int next = it.next();
1391 assertEquals(3, next);
1393 assertEquals(6, next);
1394 assertFalse(it.hasNext());
1396 // [start,end] does not contain a start of a region
1397 // no regions to iterate over
1398 it = h.getBoundedStartIterator(4, 5);
1399 assertFalse(it.hasNext());
1401 // [start,end] fully contains 1 region and start of last
1402 // - 2 regions returned
1403 it = h.getBoundedStartIterator(3, 7);
1404 assertTrue(it.hasNext());
1406 assertEquals(3, next);
1408 assertEquals(6, next);
1409 assertFalse(it.hasNext());
1411 // [start,end] contains whole of last region
1412 // - 1 region returned
1413 it = h.getBoundedStartIterator(4, 20);
1414 assertTrue(it.hasNext());
1416 assertEquals(6, next);
1417 assertFalse(it.hasNext());