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.ArrayList;
33 import java.util.Arrays;
34 import java.util.BitSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Random;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.Test;
42 public class HiddenColumnsTest
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
53 * Test the method which counts the number of hidden columns
55 @Test(groups = { "Functional" })
56 public void testGetSize()
58 HiddenColumns hidden = new HiddenColumns();
59 assertEquals(0, hidden.getSize());
61 hidden.hideColumns(3, 5);
62 assertEquals(3, hidden.getSize());
64 hidden.hideColumns(8, 8);
65 assertEquals(4, hidden.getSize());
67 hidden.hideColumns(9, 14);
68 assertEquals(10, hidden.getSize());
70 ColumnSelection cs = new ColumnSelection();
71 hidden.revealAllHiddenColumns(cs);
72 assertEquals(0, hidden.getSize());
76 * Test the method that finds the visible column position of an alignment
77 * column, allowing for hidden columns.
79 @Test(groups = { "Functional" })
80 public void testFindColumnPosition()
82 HiddenColumns cs = new HiddenColumns();
83 assertEquals(5, cs.findColumnPosition(5));
85 // hiding column 6 makes no difference
87 assertEquals(5, cs.findColumnPosition(5));
89 // hiding column 4 moves column 5 to column 4
91 assertEquals(4, cs.findColumnPosition(5));
93 // hiding column 4 moves column 4 to position 3
94 assertEquals(3, cs.findColumnPosition(4));
96 // hiding columns 1 and 2 moves column 5 to column 2
98 assertEquals(2, cs.findColumnPosition(5));
100 // check with > 1 hidden column regions
101 // where some columns are in the hidden regions
102 HiddenColumns cs2 = new HiddenColumns();
103 cs2.hideColumns(5, 10);
104 cs2.hideColumns(20, 27);
105 cs2.hideColumns(40, 44);
107 // hiding columns 5-10 and 20-27 moves column 8 to column 4
108 assertEquals(4, cs2.findColumnPosition(8));
110 // and moves column 24 to 13
111 assertEquals(13, cs2.findColumnPosition(24));
113 // and moves column 28 to 14
114 assertEquals(14, cs2.findColumnPosition(28));
116 // and moves column 40 to 25
117 assertEquals(25, cs2.findColumnPosition(40));
119 // check when hidden columns start at 0 that the visible column
121 HiddenColumns cs3 = new HiddenColumns();
122 cs3.hideColumns(0, 4);
123 assertEquals(0, cs3.findColumnPosition(2));
128 * Test the method that finds the visible column position a given distance
129 * before another column
131 @Test(groups = { "Functional" })
132 public void testFindColumnNToLeft()
134 HiddenColumns cs = new HiddenColumns();
136 // test that without hidden columns, findColumnNToLeft returns
137 // position n to left of provided position
138 long pos = cs.subtractVisibleColumns(3, 10);
139 assertEquals(7, pos);
141 // 0 returns same position
142 pos = cs.subtractVisibleColumns(0, 10);
143 assertEquals(10, pos);
145 // overflow to left returns negative number
146 pos = cs.subtractVisibleColumns(3, 0);
147 assertEquals(-3, pos);
149 // test that with hidden columns to left of result column
150 // behaviour is the same as above
151 cs.hideColumns(1, 3);
153 // position n to left of provided position
154 pos = cs.subtractVisibleColumns(3, 10);
155 assertEquals(7, pos);
157 // 0 returns same position
158 pos = cs.subtractVisibleColumns(0, 10);
159 assertEquals(10, pos);
161 // test with one set of hidden columns between start and required position
162 cs.hideColumns(12, 15);
163 pos = cs.subtractVisibleColumns(8, 17);
164 assertEquals(5, pos);
166 // test with two sets of hidden columns between start and required position
167 cs.hideColumns(20, 21);
168 pos = cs.subtractVisibleColumns(8, 23);
169 assertEquals(9, pos);
171 // repeat last 2 tests with no hidden columns to left of required position
172 ColumnSelection colsel = new ColumnSelection();
173 cs.revealAllHiddenColumns(colsel);
175 // test with one set of hidden columns between start and required position
176 cs.hideColumns(12, 15);
177 pos = cs.subtractVisibleColumns(8, 17);
178 assertEquals(5, pos);
180 // test with two sets of hidden columns between start and required position
181 cs.hideColumns(20, 21);
182 pos = cs.subtractVisibleColumns(8, 23);
183 assertEquals(9, pos);
187 @Test(groups = { "Functional" })
188 public void testGetVisibleContigs()
190 HiddenColumns cs = new HiddenColumns();
192 int[] visible = cs.getVisibleContigs(3, 10);
193 assertEquals("[3, 9]", Arrays.toString(visible));
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.getVisibleContigs(1, 13);
203 assertEquals("[1, 2, 7, 7, 10, 11]", Arrays.toString(visible));
205 // Test start hidden, end visible
206 visible = cs.getVisibleContigs(4, 14);
207 assertEquals("[7, 7, 10, 11, 13, 13]", Arrays.toString(visible));
209 // Test start hidden, end hidden
210 visible = cs.getVisibleContigs(3, 10);
211 assertEquals("[7, 7]", Arrays.toString(visible));
213 // Test start visible, end hidden
214 visible = cs.getVisibleContigs(0, 13);
215 assertEquals("[0, 2, 7, 7, 10, 11]", Arrays.toString(visible));
218 visible = cs.getVisibleContigs(4, 6);
219 assertEquals("[]", Arrays.toString(visible));
222 @Test(groups = { "Functional" })
223 public void testEquals()
225 HiddenColumns cs = new HiddenColumns();
226 cs.hideColumns(5, 9);
228 // a different set of hidden columns
229 HiddenColumns cs2 = new HiddenColumns();
231 // with no hidden columns
232 assertFalse(cs.equals(cs2));
233 assertFalse(cs2.equals(cs));
235 // with hidden columns added in a different order
236 cs2.hideColumns(6, 9);
237 cs2.hideColumns(5, 8);
239 assertTrue(cs.equals(cs2));
240 assertTrue(cs.equals(cs));
241 assertTrue(cs2.equals(cs));
242 assertTrue(cs2.equals(cs2));
245 @Test(groups = "Functional")
246 public void testCopyConstructor()
248 HiddenColumns cs = new HiddenColumns();
249 cs.hideColumns(10, 11);
250 cs.hideColumns(5, 7);
251 assertEquals("[5, 7]",
252 Arrays.toString(cs.getHiddenColumnsCopy().get(0)));
254 HiddenColumns cs2 = new HiddenColumns(cs);
255 assertTrue(cs2.hasHiddenColumns());
256 assertEquals(2, cs2.getHiddenColumnsCopy().size());
257 // hidden columns are held in column order
258 assertEquals("[5, 7]",
259 Arrays.toString(cs2.getHiddenColumnsCopy().get(0)));
260 assertEquals("[10, 11]",
261 Arrays.toString(cs2.getHiddenColumnsCopy().get(1)));
265 * Test the code used to locate the reference sequence ruler origin
267 @Test(groups = { "Functional" })
268 public void testLocateVisibleBoundsofSequence()
270 // create random alignment
271 AlignmentGenerator gen = new AlignmentGenerator(false);
272 AlignmentI al = gen.generate(50, 20, 123, 5, 5);
274 HiddenColumns cs = al.getHiddenColumns();
275 ColumnSelection colsel = new ColumnSelection();
277 SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
278 assertEquals(2, seq.findIndex(seq.getStart()));
282 Arrays.toString(new int[]
283 { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getStart()) - 1,
284 seq.findIndex(seq.getEnd()) - 1 }),
285 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
287 // hidden column on gap after end of sequence - should not affect bounds
288 colsel.hideSelectedColumns(13, al.getHiddenColumns());
290 Arrays.toString(new int[]
291 { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getStart()) - 1,
292 seq.findIndex(seq.getEnd()) - 1 }),
293 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
295 cs.revealAllHiddenColumns(colsel);
296 // hidden column on gap before beginning of sequence - should vis bounds by
298 colsel.hideSelectedColumns(0, al.getHiddenColumns());
300 Arrays.toString(new int[]
301 { seq.findIndex(seq.getStart()) - 2, seq.findIndex(seq.getStart()) - 1,
302 seq.findIndex(seq.getEnd()) - 1 }),
303 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
305 cs.revealAllHiddenColumns(colsel);
306 // hide columns around most of sequence - leave one residue remaining
307 cs.hideColumns(1, 3);
308 cs.hideColumns(6, 11);
310 cs.getVisibleSequenceStrings(0, 5, new SequenceI[]
316 { 1, seq.findIndex(seq.getStart()) - 1,
317 seq.findIndex(seq.getEnd()) - 1 }),
318 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
319 cs.revealAllHiddenColumns(colsel);
321 // hide whole sequence - should just get location of hidden region
322 // containing sequence
323 cs.hideColumns(1, 11);
327 { 0, seq.findIndex(seq.getStart()) - 1,
328 seq.findIndex(seq.getEnd()) - 1 }),
329 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
331 cs.revealAllHiddenColumns(colsel);
332 cs.hideColumns(0, 15);
335 { 0, seq.findIndex(seq.getStart()) - 1,
336 seq.findIndex(seq.getEnd()) - 1 }),
337 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
339 SequenceI seq2 = new Sequence("RefSeq2", "-------A-SD-ASD--E---");
341 cs.revealAllHiddenColumns(colsel);
342 cs.hideColumns(7, 17);
346 { 0, seq2.findIndex(seq2.getStart()) - 1,
347 seq2.findIndex(seq2.getEnd()) - 1 }),
348 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
350 cs.revealAllHiddenColumns(colsel);
351 cs.hideColumns(3, 17);
355 { 0, seq2.findIndex(seq2.getStart()) - 1,
356 seq2.findIndex(seq2.getEnd()) - 1 }),
357 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
359 cs.revealAllHiddenColumns(colsel);
360 cs.hideColumns(3, 19);
364 { 0, seq2.findIndex(seq2.getStart()) - 1,
365 seq2.findIndex(seq2.getEnd()) - 1 }),
366 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
368 cs.revealAllHiddenColumns(colsel);
369 cs.hideColumns(0, 0);
370 int[] test = cs.locateVisibleBoundsOfSequence(seq);
371 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
372 Arrays.toString(test));
374 cs.revealAllHiddenColumns(colsel);
375 cs.hideColumns(0, 1);
376 test = cs.locateVisibleBoundsOfSequence(seq);
377 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
378 Arrays.toString(test));
380 cs.revealAllHiddenColumns(colsel);
381 cs.hideColumns(0, 2);
382 test = cs.locateVisibleBoundsOfSequence(seq);
383 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
384 Arrays.toString(test));
386 cs.revealAllHiddenColumns(colsel);
387 cs.hideColumns(1, 1);
388 test = cs.locateVisibleBoundsOfSequence(seq);
389 assertEquals(Arrays.toString(new int[] { 2, 1, 11 }),
390 Arrays.toString(test));
392 cs.revealAllHiddenColumns(colsel);
393 cs.hideColumns(1, 2);
394 test = cs.locateVisibleBoundsOfSequence(seq);
395 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
396 Arrays.toString(test));
398 cs.revealAllHiddenColumns(colsel);
399 cs.hideColumns(1, 3);
400 test = cs.locateVisibleBoundsOfSequence(seq);
401 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
402 Arrays.toString(test));
404 cs.revealAllHiddenColumns(colsel);
405 cs.hideColumns(0, 2);
406 cs.hideColumns(5, 6);
407 test = cs.locateVisibleBoundsOfSequence(seq);
408 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
409 Arrays.toString(test));
411 cs.revealAllHiddenColumns(colsel);
412 cs.hideColumns(0, 2);
413 cs.hideColumns(5, 6);
414 cs.hideColumns(9, 10);
415 test = cs.locateVisibleBoundsOfSequence(seq);
416 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
417 Arrays.toString(test));
419 cs.revealAllHiddenColumns(colsel);
420 cs.hideColumns(0, 2);
421 cs.hideColumns(7, 11);
422 test = cs.locateVisibleBoundsOfSequence(seq);
423 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
424 Arrays.toString(test));
426 cs.revealAllHiddenColumns(colsel);
427 cs.hideColumns(2, 4);
428 cs.hideColumns(7, 11);
429 test = cs.locateVisibleBoundsOfSequence(seq);
430 assertEquals(Arrays.toString(new int[] { 1, 1, 11 }),
431 Arrays.toString(test));
433 cs.revealAllHiddenColumns(colsel);
434 cs.hideColumns(2, 4);
435 cs.hideColumns(7, 12);
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(1, 11);
442 test = cs.locateVisibleBoundsOfSequence(seq);
443 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
444 Arrays.toString(test));
446 cs.revealAllHiddenColumns(colsel);
447 cs.hideColumns(0, 12);
448 test = cs.locateVisibleBoundsOfSequence(seq);
449 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
450 Arrays.toString(test));
452 cs.revealAllHiddenColumns(colsel);
453 cs.hideColumns(0, 4);
454 cs.hideColumns(6, 12);
455 test = cs.locateVisibleBoundsOfSequence(seq);
456 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
457 Arrays.toString(test));
459 cs.revealAllHiddenColumns(colsel);
460 cs.hideColumns(0, 1);
461 cs.hideColumns(3, 12);
462 test = cs.locateVisibleBoundsOfSequence(seq);
463 assertEquals(Arrays.toString(new int[] { 0, 1, 11 }),
464 Arrays.toString(test));
466 // These tests cover different behaviour to original
467 // locateVisibleBoundsOfSequence
468 // Previously first values of each were 3,9 and 6 respectively.
469 cs.revealAllHiddenColumns(colsel);
470 cs.hideColumns(3, 14);
471 cs.hideColumns(17, 19);
475 { 3, seq2.findIndex(seq2.getStart()) - 1,
476 seq2.findIndex(seq2.getEnd()) - 1 }),
477 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
479 cs.revealAllHiddenColumns(colsel);
480 cs.hideColumns(3, 7);
481 cs.hideColumns(9, 14);
482 cs.hideColumns(17, 19);
486 { 9, seq2.findIndex(seq2.getStart()) - 1,
487 seq2.findIndex(seq2.getEnd()) - 1 }),
488 Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2)));
490 cs.revealAllHiddenColumns(colsel);
491 cs.hideColumns(0, 1);
492 cs.hideColumns(3, 4);
493 cs.hideColumns(6, 8);
494 cs.hideColumns(10, 12);
495 test = cs.locateVisibleBoundsOfSequence(seq);
496 assertEquals(Arrays.toString(new int[] { 6, 1, 11 }),
497 Arrays.toString(test));
501 @Test(groups = { "Functional" })
502 public void testLocateVisibleBoundsPathologicals()
504 // test some pathological cases we missed
505 AlignmentI al = new Alignment(
507 { new Sequence("refseqGaptest", "KTDVTI----------NFI-----G----L") });
508 HiddenColumns cs = new HiddenColumns();
509 cs.hideInsertionsFor(al.getSequenceAt(0));
511 + al.getSequenceAt(0).getCharAt(cs.adjustForHiddenColumns(9)));
515 @Test(groups = { "Functional" })
516 public void testHideColumns()
518 // create random alignment
519 AlignmentGenerator gen = new AlignmentGenerator(false);
520 AlignmentI al = gen.generate(50, 20, 123, 5, 5);
522 ColumnSelection colsel = new ColumnSelection();
523 HiddenColumns cs = al.getHiddenColumns();
524 colsel.hideSelectedColumns(5, al.getHiddenColumns());
525 List<int[]> hidden = cs.getHiddenColumnsCopy();
526 assertEquals(1, hidden.size());
527 assertEquals("[5, 5]", Arrays.toString(hidden.get(0)));
529 colsel.hideSelectedColumns(3, al.getHiddenColumns());
530 hidden = cs.getHiddenColumnsCopy();
531 assertEquals(2, hidden.size());
532 // two hidden ranges, in order:
533 assertEquals(hidden.size(), cs.getHiddenColumnsCopy().size());
534 assertEquals("[3, 3]", Arrays.toString(hidden.get(0)));
535 assertEquals("[5, 5]", Arrays.toString(hidden.get(1)));
537 // hiding column 4 expands [3, 3] to [3, 4]
538 // and merges to [5, 5] to make [3, 5]
539 colsel.hideSelectedColumns(4, al.getHiddenColumns());
540 hidden = cs.getHiddenColumnsCopy();
541 assertEquals(1, hidden.size());
542 assertEquals("[3, 5]", Arrays.toString(hidden.get(0)));
544 // clear hidden columns (note they are added to selected)
545 cs.revealAllHiddenColumns(colsel);
546 // it is now actually null but getter returns an empty list
547 assertTrue(cs.getHiddenColumnsCopy().isEmpty());
549 cs.hideColumns(3, 6);
550 hidden = cs.getHiddenColumnsCopy();
551 int[] firstHiddenRange = hidden.get(0);
552 assertEquals("[3, 6]", Arrays.toString(firstHiddenRange));
554 // adding a subrange of already hidden should do nothing
555 cs.hideColumns(4, 5);
556 hidden = cs.getHiddenColumnsCopy();
557 assertEquals(1, hidden.size());
558 assertEquals("[3, 6]",
559 Arrays.toString(cs.getHiddenColumnsCopy().get(0)));
560 cs.hideColumns(3, 5);
561 hidden = cs.getHiddenColumnsCopy();
562 assertEquals(1, hidden.size());
563 assertEquals("[3, 6]",
564 Arrays.toString(cs.getHiddenColumnsCopy().get(0)));
565 cs.hideColumns(4, 6);
566 hidden = cs.getHiddenColumnsCopy();
567 assertEquals(1, hidden.size());
568 assertEquals("[3, 6]",
569 Arrays.toString(cs.getHiddenColumnsCopy().get(0)));
570 cs.hideColumns(3, 6);
571 hidden = cs.getHiddenColumnsCopy();
572 assertEquals(1, hidden.size());
573 assertEquals("[3, 6]",
574 Arrays.toString(cs.getHiddenColumnsCopy().get(0)));
576 cs.revealAllHiddenColumns(colsel);
577 cs.hideColumns(2, 4);
578 hidden = cs.getHiddenColumnsCopy();
579 assertEquals(1, hidden.size());
580 assertEquals("[2, 4]", Arrays.toString(hidden.get(0)));
582 // extend contiguous with 2 positions overlap
583 cs.hideColumns(3, 5);
584 hidden = cs.getHiddenColumnsCopy();
585 assertEquals(1, hidden.size());
586 assertEquals("[2, 5]", Arrays.toString(hidden.get(0)));
588 // extend contiguous with 1 position overlap
589 cs.hideColumns(5, 6);
590 hidden = cs.getHiddenColumnsCopy();
591 assertEquals(1, hidden.size());
592 assertEquals("[2, 6]", Arrays.toString(hidden.get(0)));
594 // extend contiguous with overlap both ends:
595 cs.hideColumns(1, 7);
596 hidden = cs.getHiddenColumnsCopy();
597 assertEquals(1, hidden.size());
598 assertEquals("[1, 7]", Arrays.toString(hidden.get(0)));
602 * Test the method that reveals a range of hidden columns given the start
603 * column of the range
605 @Test(groups = { "Functional" })
606 public void testRevealHiddenColumns()
608 ColumnSelection colsel = new ColumnSelection();
609 HiddenColumns cs = new HiddenColumns();
610 cs.hideColumns(5, 8);
611 colsel.addElement(10);
612 cs.revealHiddenColumns(5, colsel);
614 // hiddenColumns now empty
615 assertEquals(0, cs.getSize());
617 // revealed columns are marked as selected (added to selection):
618 assertEquals("[10, 5, 6, 7, 8]", colsel.getSelected().toString());
620 // calling with a column other than the range start does nothing:
621 colsel = new ColumnSelection();
622 cs = new HiddenColumns();
623 cs.hideColumns(5, 8);
625 int prevSize = cs.getSize();
626 cs.revealHiddenColumns(6, colsel);
627 assertEquals(prevSize, cs.getSize());
628 assertTrue(colsel.getSelected().isEmpty());
631 @Test(groups = { "Functional" })
632 public void testRevealAllHiddenColumns()
634 HiddenColumns hidden = new HiddenColumns();
635 ColumnSelection colsel = new ColumnSelection();
636 hidden.hideColumns(5, 8);
637 hidden.hideColumns(2, 3);
638 colsel.addElement(11);
639 colsel.addElement(1);
640 hidden.revealAllHiddenColumns(colsel);
643 * revealing hidden columns adds them (in order) to the (unordered)
647 // hiddenColumns now empty
648 assertEquals(0, hidden.getSize());
650 assertEquals("[11, 1, 2, 3, 5, 6, 7, 8]",
651 colsel.getSelected().toString());
654 @Test(groups = { "Functional" })
655 public void testIsVisible()
657 HiddenColumns cs = new HiddenColumns();
658 cs.hideColumns(2, 4);
659 cs.hideColumns(6, 7);
660 assertTrue(cs.isVisible(0));
661 assertTrue(cs.isVisible(-99));
662 assertTrue(cs.isVisible(1));
663 assertFalse(cs.isVisible(2));
664 assertFalse(cs.isVisible(3));
665 assertFalse(cs.isVisible(4));
666 assertTrue(cs.isVisible(5));
667 assertFalse(cs.isVisible(6));
668 assertFalse(cs.isVisible(7));
672 * Test for the case when a hidden range encloses more one already hidden
675 @Test(groups = { "Functional" })
676 public void testHideColumns_subsumingHidden()
679 * JAL-2370 bug scenario:
680 * two hidden ranges subsumed by a third
682 HiddenColumns cs = new HiddenColumns();
683 cs.hideColumns(49, 59);
684 cs.hideColumns(69, 79);
685 List<int[]> hidden = cs.getHiddenColumnsCopy();
686 assertEquals(2, hidden.size());
687 assertEquals("[49, 59]", Arrays.toString(hidden.get(0)));
688 assertEquals("[69, 79]", Arrays.toString(hidden.get(1)));
690 cs.hideColumns(48, 80);
691 hidden = cs.getHiddenColumnsCopy();
692 assertEquals(1, hidden.size());
693 assertEquals("[48, 80]", Arrays.toString(hidden.get(0)));
696 * another...joining hidden ranges
698 cs = new HiddenColumns();
699 cs.hideColumns(10, 20);
700 cs.hideColumns(30, 40);
701 cs.hideColumns(50, 60);
702 // hiding 21-49 should merge to one range
703 cs.hideColumns(21, 49);
704 hidden = cs.getHiddenColumnsCopy();
705 assertEquals(1, hidden.size());
706 assertEquals("[10, 60]", Arrays.toString(hidden.get(0)));
709 * another...left overlap, subsumption, right overlap,
710 * no overlap of existing hidden ranges
712 cs = new HiddenColumns();
713 cs.hideColumns(10, 20);
714 cs.hideColumns(10, 20);
715 cs.hideColumns(30, 35);
716 cs.hideColumns(40, 50);
717 cs.hideColumns(60, 70);
719 cs.hideColumns(15, 45);
720 hidden = cs.getHiddenColumnsCopy();
721 assertEquals(2, hidden.size());
722 assertEquals("[10, 50]", Arrays.toString(hidden.get(0)));
723 assertEquals("[60, 70]", Arrays.toString(hidden.get(1)));
726 @Test(groups = { "Functional" })
727 public void testHideBitset()
731 BitSet one = new BitSet();
735 cs = new HiddenColumns();
736 cs.hideMarkedBits(one);
737 assertEquals(1, cs.getHiddenColumnsCopy().size());
740 cs = new HiddenColumns();
741 cs.hideMarkedBits(one);
742 assertEquals(1, cs.getHiddenColumnsCopy().size());
745 cs = new HiddenColumns();
746 cs.hideMarkedBits(one);
747 assertEquals(1, cs.getHiddenColumnsCopy().size());
751 cs = new HiddenColumns();
752 cs.hideMarkedBits(one);
753 assertEquals(2, cs.getHiddenColumnsCopy().size());
755 assertEquals(0, cs.adjustForHiddenColumns(0));
756 assertEquals(2, cs.adjustForHiddenColumns(1));
757 assertEquals(4, cs.adjustForHiddenColumns(2));
761 cs = new HiddenColumns();
762 cs.hideMarkedBits(one);
764 assertEquals(1, cs.getHiddenColumnsCopy().size());
766 assertEquals(0, cs.adjustForHiddenColumns(0));
767 assertEquals(1, cs.adjustForHiddenColumns(1));
768 assertEquals(2, cs.adjustForHiddenColumns(2));
769 assertEquals(4, cs.adjustForHiddenColumns(3));
772 @Test(groups = { "Functional" })
773 public void testMarkHiddenRegions()
775 BitSet toMark, fromMark;
776 long seed = -3241532;
777 Random number = new Random(seed);
778 for (int n = 0; n < 1000; n++)
780 // create a random bitfield
783 { number.nextLong(), number.nextLong(), number.nextLong() });
784 toMark.set(n * number.nextInt(10), n * (25 + number.nextInt(25)));
785 HiddenColumns hc = new HiddenColumns();
786 hc.hideMarkedBits(toMark);
788 // see if we can recover bitfield
789 hc.markHiddenRegions(fromMark = new BitSet());
790 assertEquals(toMark, fromMark);
794 @Test(groups = { "Functional" })
795 public void testFindHiddenRegionPositions()
797 HiddenColumns hc = new HiddenColumns();
799 List<Integer> positions = hc.findHiddenRegionPositions(0, 20);
800 assertTrue(positions.isEmpty());
802 hc.hideColumns(3, 7);
803 hc.hideColumns(10, 10);
804 hc.hideColumns(14, 15);
806 positions = hc.findHiddenRegionPositions(0, 20);
807 assertEquals(3, positions.size());
808 assertEquals(3, positions.get(0).intValue());
809 assertEquals(5, positions.get(1).intValue());
810 assertEquals(8, positions.get(2).intValue());
812 positions = hc.findHiddenRegionPositions(7, 20);
813 assertEquals(2, positions.size());
814 assertEquals(5, positions.get(0).intValue());
815 assertEquals(8, positions.get(1).intValue());
817 positions = hc.findHiddenRegionPositions(11, 13);
818 assertEquals(0, positions.size());
820 positions = hc.findHiddenRegionPositions(7, 20);
821 assertEquals(2, positions.size());
822 assertEquals(5, positions.get(0).intValue());
823 assertEquals(8, positions.get(1).intValue());
825 positions = hc.findHiddenRegionPositions(0, 1);
826 assertEquals(0, positions.size());
828 positions = hc.findHiddenRegionPositions(17, 20);
829 assertEquals(0, positions.size());
831 positions = hc.findHiddenRegionPositions(10, 15);
832 assertEquals(2, positions.size());
833 assertEquals(5, positions.get(0).intValue());
834 assertEquals(8, positions.get(1).intValue());
837 @Test(groups = { "Functional" })
838 public void testRegionsToString()
840 HiddenColumns hc = new HiddenColumns();
842 String result = hc.regionsToString(",", "--");
843 assertEquals("", result);
845 hc.hideColumns(3, 7);
846 hc.hideColumns(10, 10);
847 hc.hideColumns(14, 15);
849 result = hc.regionsToString(",", "--");
850 assertEquals("3--7,10--10,14--15", result);
853 @Test(groups = "Functional")
854 public void testGetVisibleStartAndEndIndexTest()
856 Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
857 AlignmentI align = new Alignment(new SequenceI[] { seq });
858 HiddenColumns hc = new HiddenColumns();
860 int[] startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
861 assertEquals(0, startEnd[0]);
862 assertEquals(25, startEnd[1]);
864 hc.hideColumns(0, 0);
865 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
866 assertEquals(1, startEnd[0]);
867 assertEquals(25, startEnd[1]);
869 hc.hideColumns(6, 9);
870 hc.hideColumns(11, 12);
871 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
872 assertEquals(1, startEnd[0]);
873 assertEquals(25, startEnd[1]);
875 hc.hideColumns(24, 25);
876 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
877 System.out.println(startEnd[0] + " : " + startEnd[1]);
878 assertEquals(1, startEnd[0]);
879 assertEquals(23, startEnd[1]);
882 @Test(groups = "Functional")
883 public void testGetRegionWithEdgeAtRes()
885 HiddenColumns hc = new HiddenColumns();
887 int[] result = hc.getRegionWithEdgeAtRes(5);
890 hc.hideColumns(3, 7);
891 hc.hideColumns(10, 10);
892 hc.hideColumns(14, 15);
894 result = hc.getRegionWithEdgeAtRes(2);
895 assertEquals(3, result[0]);
896 assertEquals(7, result[1]);
898 result = hc.getRegionWithEdgeAtRes(5);
899 assertEquals(10, result[0]);
900 assertEquals(10, result[1]);
902 result = hc.getRegionWithEdgeAtRes(6);
905 result = hc.getRegionWithEdgeAtRes(0);
908 result = hc.getRegionWithEdgeAtRes(7);
909 assertEquals(14, result[0]);
910 assertEquals(15, result[1]);
912 result = hc.getRegionWithEdgeAtRes(8);
913 assertEquals(14, result[0]);
914 assertEquals(15, result[1]);
917 @Test(groups = "Functional")
918 public void testPropagateInsertions()
920 // create an alignment with no gaps - this will be the profile seq and other
922 AlignmentGenerator gen = new AlignmentGenerator(false);
923 AlignmentI al = gen.generate(25, 10, 1234, 0, 0);
925 // get the profileseq
926 SequenceI profileseq = al.getSequenceAt(0);
927 SequenceI gappedseq = new Sequence(profileseq);
928 gappedseq.insertCharAt(5, al.getGapCharacter());
929 gappedseq.insertCharAt(6, al.getGapCharacter());
930 gappedseq.insertCharAt(7, al.getGapCharacter());
931 gappedseq.insertCharAt(8, al.getGapCharacter());
933 // create an alignment view with the gapped sequence
934 SequenceI[] seqs = new SequenceI[1];
936 AlignmentI newal = new Alignment(seqs);
937 HiddenColumns hidden = new HiddenColumns();
938 hidden.hideColumns(15, 17);
940 AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
943 // confirm that original contigs are as expected
944 int[] oldcontigs = hidden.getVisibleContigs(0, 25);
945 int[] testcontigs = { 0, 14, 18, 24 };
946 assertTrue(Arrays.equals(oldcontigs, testcontigs));
948 // propagate insertions
949 HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
952 // confirm that the contigs have changed to account for the gaps
953 int[] newcontigs = result.getVisibleContigs(0, 25);
956 assertTrue(Arrays.equals(newcontigs, testcontigs));
958 // confirm the alignment has been changed so that the other sequences have
959 // gaps inserted where the columns are hidden
960 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[10]));
961 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[11]));
962 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[12]));
963 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[13]));
964 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[14]));
968 @Test(groups = "Functional")
969 public void testPropagateInsertionsOverlap()
971 // test propagateInsertions where gaps and hiddenColumns overlap
973 // create an alignment with no gaps - this will be the profile seq and other
975 AlignmentGenerator gen = new AlignmentGenerator(false);
976 AlignmentI al = gen.generate(20, 10, 1234, 0, 0);
978 // get the profileseq
979 SequenceI profileseq = al.getSequenceAt(0);
980 SequenceI gappedseq = new Sequence(profileseq);
981 gappedseq.insertCharAt(5, al.getGapCharacter());
982 gappedseq.insertCharAt(6, al.getGapCharacter());
983 gappedseq.insertCharAt(7, al.getGapCharacter());
984 gappedseq.insertCharAt(8, al.getGapCharacter());
986 // create an alignment view with the gapped sequence
987 SequenceI[] seqs = new SequenceI[1];
989 AlignmentI newal = new Alignment(seqs);
991 // hide columns so that some overlap with the gaps
992 HiddenColumns hidden = new HiddenColumns();
993 hidden.hideColumns(7, 10);
995 AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
998 // confirm that original contigs are as expected
999 int[] oldcontigs = hidden.getVisibleContigs(0, 20);
1000 int[] testcontigs = { 0, 6, 11, 19 };
1001 assertTrue(Arrays.equals(oldcontigs, testcontigs));
1003 // propagate insertions
1004 HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
1007 // confirm that the contigs have changed to account for the gaps
1008 int[] newcontigs = result.getVisibleContigs(0, 20);
1011 assertTrue(Arrays.equals(newcontigs, testcontigs));
1013 // confirm the alignment has been changed so that the other sequences have
1014 // gaps inserted where the columns are hidden
1015 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[4]));
1016 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[5]));
1017 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[6]));
1018 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[7]));
1021 @Test(groups = "Functional")
1022 public void testHasHiddenColumns()
1024 HiddenColumns h = new HiddenColumns();
1026 // new HiddenColumns2 has no hidden cols
1027 assertFalse(h.hasHiddenColumns());
1029 // some columns hidden, returns true
1030 h.hideColumns(5, 10);
1031 assertTrue(h.hasHiddenColumns());
1033 // reveal columns, no hidden cols again
1034 ColumnSelection sel = new ColumnSelection();
1035 h.revealAllHiddenColumns(sel);
1036 assertFalse(h.hasHiddenColumns());
1039 @Test(groups = "Functional")
1040 public void testHasManyHiddenColumns()
1042 HiddenColumns h = new HiddenColumns();
1044 // new HiddenColumns2 has no hidden cols
1045 assertFalse(h.hasManyHiddenColumns());
1047 // one set of columns hidden, returns false
1048 h.hideColumns(5, 10);
1049 assertFalse(h.hasManyHiddenColumns());
1051 // two sets hidden, returns true
1052 h.hideColumns(15, 17);
1053 assertTrue(h.hasManyHiddenColumns());
1055 // back to one block, asserts false
1056 h.hideColumns(11, 14);
1057 assertFalse(h.hasManyHiddenColumns());
1060 @Test(groups = "Functional")
1061 public void testAdjustForHiddenColumns()
1063 HiddenColumns h = new HiddenColumns();
1064 // returns input value when there are no hidden columns
1065 assertEquals(10, h.adjustForHiddenColumns(10));
1067 h.hideColumns(20, 30);
1068 assertEquals(10, h.adjustForHiddenColumns(10));
1069 assertEquals(20 + 11, h.adjustForHiddenColumns(20));
1070 assertEquals(35 + 11, h.adjustForHiddenColumns(35));
1072 h.hideColumns(5, 7);
1073 assertEquals(10 + 3, h.adjustForHiddenColumns(10));
1074 assertEquals(20 + 14, h.adjustForHiddenColumns(20));
1075 assertEquals(35 + 14, h.adjustForHiddenColumns(35));
1077 ColumnSelection sel = new ColumnSelection();
1078 h.revealAllHiddenColumns(sel);
1079 h.hideColumns(0, 1);
1080 assertEquals(4, h.adjustForHiddenColumns(2));
1083 @Test(groups = "Functional")
1084 public void testGetHiddenBoundaryLeft()
1086 HiddenColumns h = new HiddenColumns();
1088 // returns same value if no hidden cols
1089 assertEquals(3, h.getHiddenBoundaryLeft(3));
1091 h.hideColumns(5, 10);
1092 assertEquals(10, h.getHiddenBoundaryLeft(15));
1093 assertEquals(3, h.getHiddenBoundaryLeft(3));
1094 assertEquals(7, h.getHiddenBoundaryLeft(7));
1096 h.hideColumns(15, 20);
1097 assertEquals(10, h.getHiddenBoundaryLeft(15));
1098 assertEquals(20, h.getHiddenBoundaryLeft(21));
1101 @Test(groups = "Functional")
1102 public void testGetHiddenBoundaryRight()
1104 HiddenColumns h = new HiddenColumns();
1106 // returns same value if no hidden cols
1107 assertEquals(3, h.getHiddenBoundaryRight(3));
1109 h.hideColumns(5, 10);
1110 assertEquals(5, h.getHiddenBoundaryRight(3));
1111 assertEquals(15, h.getHiddenBoundaryRight(15));
1112 assertEquals(7, h.getHiddenBoundaryRight(7));
1114 h.hideColumns(15, 20);
1115 assertEquals(15, h.getHiddenBoundaryRight(7));
1116 assertEquals(15, h.getHiddenBoundaryRight(14));
1119 @Test(groups = "Functional")
1120 public void testGetHiddenColumnsCopy()
1122 HiddenColumns h = new HiddenColumns();
1123 ArrayList<int[]> result = h.getHiddenColumnsCopy();
1124 assertTrue(result.isEmpty());
1126 h.hideColumns(5, 10);
1127 result = h.getHiddenColumnsCopy();
1128 assertEquals(1, result.size());
1129 assertEquals(5, result.get(0)[0]);
1130 assertEquals(10, result.get(0)[1]);
1132 h.hideColumns(22, 23);
1133 result = h.getHiddenColumnsCopy();
1134 assertEquals(2, result.size());
1135 assertEquals(5, result.get(0)[0]);
1136 assertEquals(10, result.get(0)[1]);
1137 assertEquals(22, result.get(1)[0]);
1138 assertEquals(23, result.get(1)[1]);
1140 // test for only one hidden region at start of alignment
1141 ColumnSelection sel = new ColumnSelection();
1142 h.revealAllHiddenColumns(sel);
1143 h.hideColumns(0, 1);
1144 result = h.getHiddenColumnsCopy();
1145 assertEquals(1, result.size());
1146 assertEquals(0, result.get(0)[0]);
1147 assertEquals(1, result.get(0)[1]);
1150 @Test(groups = "Functional")
1151 public void testGetVisibleSequenceStrings()
1153 HiddenColumns h = new HiddenColumns();
1154 SequenceI seq1 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
1155 SequenceI seq2 = new Sequence("TEST2", "VICYHRNDTGA");
1156 SequenceI[] seqs = new SequenceI[2];
1159 String[] result = h.getVisibleSequenceStrings(5, 10, seqs);
1160 assertEquals(2, result.length);
1161 assertEquals("WKQES", result[0]);
1162 assertEquals("RNDTG", result[1]);
1164 h.hideColumns(6, 8);
1165 result = h.getVisibleSequenceStrings(5, 10, seqs);
1166 assertEquals(2, result.length);
1167 assertEquals("WS", result[0]);
1168 assertEquals("RG", result[1]);
1170 SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
1171 ColumnSelection sel = new ColumnSelection();
1172 h.revealAllHiddenColumns(sel);
1173 h.hideColumns(1, 3);
1174 h.hideColumns(6, 11);
1176 h.getVisibleSequenceStrings(0, 5, new SequenceI[]
1180 @Test(groups = "Functional")
1181 public void testHideInsertionsFor()
1183 HiddenColumns h = new HiddenColumns();
1184 HiddenColumns h2 = new HiddenColumns();
1185 SequenceI seq1 = new Sequence("TEST1", "GAL---MFW-KQESPVICY--HRNDT");
1186 SequenceI seq2 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
1188 h.hideInsertionsFor(seq2);
1189 assertTrue(h.equals(h2));
1191 h.hideInsertionsFor(seq1);
1192 h2.hideColumns(3, 5);
1193 h2.hideColumns(9, 9);
1194 h2.hideColumns(19, 20);
1195 assertTrue(h.equals(h2));
1198 @Test(groups = "Functional")
1199 public void testHideMarkedBits()
1201 HiddenColumns h = new HiddenColumns();
1202 HiddenColumns h2 = new HiddenColumns();
1204 BitSet tohide = new BitSet(21);
1205 h.hideMarkedBits(tohide);
1206 assertTrue(h.equals(h2));
1208 // NB in hideMarkedBits, the last bit is not set to hidden
1212 h.hideMarkedBits(tohide);
1214 h2.hideColumns(3, 5);
1215 h2.hideColumns(9, 9);
1216 h2.hideColumns(19, 20);
1217 assertTrue(h.equals(h2));
1220 @Test(groups = "Functional")
1221 public void testMakeVisibleAnnotation()
1223 HiddenColumns h = new HiddenColumns();
1224 Annotation[] anns = new Annotation[] { null, null, new Annotation(1),
1225 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1226 new Annotation(5), new Annotation(6), new Annotation(7),
1227 new Annotation(8) };
1228 AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an",
1231 // without hidden cols, just truncates
1232 h.makeVisibleAnnotation(3, 5, ann);
1233 assertEquals(3, ann.annotations.length);
1234 assertEquals(2.0f, ann.annotations[0].value);
1235 assertEquals(3.0f, ann.annotations[1].value);
1236 assertNull(ann.annotations[2]);
1238 anns = new Annotation[] { null, null, new Annotation(1),
1239 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1240 new Annotation(5), new Annotation(6), new Annotation(7),
1241 new Annotation(8) };
1242 ann = new AlignmentAnnotation("an", "some an", anns);
1243 h.hideColumns(4, 7);
1244 h.makeVisibleAnnotation(1, 9, ann);
1245 assertEquals(5, ann.annotations.length);
1246 assertNull(ann.annotations[0]);
1247 assertEquals(1.0f, ann.annotations[1].value);
1248 assertEquals(2.0f, ann.annotations[2].value);
1249 assertEquals(5.0f, ann.annotations[3].value);
1250 assertEquals(6.0f, ann.annotations[4].value);
1252 anns = new Annotation[] { null, null, new Annotation(1),
1253 new Annotation(2), new Annotation(3), null, null, new Annotation(4),
1254 new Annotation(5), new Annotation(6), new Annotation(7),
1255 new Annotation(8) };
1256 ann = new AlignmentAnnotation("an", "some an", anns);
1257 h.hideColumns(1, 2);
1258 h.makeVisibleAnnotation(1, 9, ann);
1259 assertEquals(3, ann.annotations.length);
1260 assertEquals(2.0f, ann.annotations[0].value);
1261 assertEquals(5.0f, ann.annotations[1].value);
1262 assertEquals(6.0f, ann.annotations[2].value);
1265 @Test(groups = "Functional")
1266 public void testSubtractVisibleColumns()
1268 HiddenColumns h = new HiddenColumns();
1269 int result = h.subtractVisibleColumns(1, 10);
1270 assertEquals(9, result);
1272 h.hideColumns(7, 9);
1273 result = h.subtractVisibleColumns(4, 10);
1274 assertEquals(3, result);
1276 h.hideColumns(14, 15);
1277 result = h.subtractVisibleColumns(4, 10);
1278 assertEquals(3, result);
1280 result = h.subtractVisibleColumns(10, 17);
1281 assertEquals(2, result);
1283 result = h.subtractVisibleColumns(1, 7);
1284 assertEquals(5, result);
1286 result = h.subtractVisibleColumns(1, 8);
1287 assertEquals(5, result);
1289 result = h.subtractVisibleColumns(3, 15);
1290 assertEquals(10, result);
1292 ColumnSelection sel = new ColumnSelection();
1293 h.revealAllHiddenColumns(sel);
1294 h.hideColumns(0, 30);
1295 result = h.subtractVisibleColumns(31, 0);
1296 assertEquals(-31, result);
1299 @Test(groups = "Functional")
1300 public void testBoundedIterator()
1302 HiddenColumns h = new HiddenColumns();
1303 Iterator<int[]> it = h.getBoundedIterator(0, 10, false);
1305 // no hidden columns = nothing to iterate over
1306 assertFalse(it.hasNext());
1308 // [start,end] contains all hidden columns
1309 // all regions are returned
1310 h.hideColumns(3, 10);
1311 h.hideColumns(14, 16);
1312 it = h.getBoundedIterator(0, 20, false);
1313 assertTrue(it.hasNext());
1314 int[] next = it.next();
1315 assertEquals(3, next[0]);
1316 assertEquals(10, next[1]);
1318 assertEquals(14, next[0]);
1319 assertEquals(16, next[1]);
1320 assertFalse(it.hasNext());
1322 // [start,end] overlaps a region
1323 // 1 region returned
1324 it = h.getBoundedIterator(5, 7, false);
1325 assertTrue(it.hasNext());
1327 assertEquals(3, next[0]);
1328 assertEquals(10, next[1]);
1329 assertFalse(it.hasNext());
1331 // [start,end] fully contains 1 region and start of last
1332 // - 2 regions returned
1333 it = h.getBoundedIterator(3, 15, false);
1334 assertTrue(it.hasNext());
1336 assertEquals(3, next[0]);
1337 assertEquals(10, next[1]);
1339 assertEquals(14, next[0]);
1340 assertEquals(16, next[1]);
1341 assertFalse(it.hasNext());
1343 // [start,end] contains end of first region and whole of last region
1344 // - 2 regions returned
1345 it = h.getBoundedIterator(4, 20, false);
1346 assertTrue(it.hasNext());
1348 assertEquals(3, next[0]);
1349 assertEquals(10, next[1]);
1351 assertEquals(14, next[0]);
1352 assertEquals(16, next[1]);
1353 assertFalse(it.hasNext());
1356 @Test(groups = "Functional")
1357 public void testBoundedStartIterator()
1359 HiddenColumns h = new HiddenColumns();
1360 Iterator<Integer> it = h.getBoundedStartIterator(0, 10, false);
1362 // no hidden columns = nothing to iterate over
1363 assertFalse(it.hasNext());
1365 // [start,end] contains all hidden columns
1366 // all regions are returned
1367 h.hideColumns(3, 10);
1368 h.hideColumns(14, 16);
1369 it = h.getBoundedStartIterator(0, 20, false);
1370 assertTrue(it.hasNext());
1371 int next = it.next();
1372 assertEquals(3, next);
1374 assertEquals(6, next);
1375 assertFalse(it.hasNext());
1377 // [start,end] does not contain a start of a region
1378 // no regions to iterate over
1379 it = h.getBoundedStartIterator(4, 5, false);
1380 assertFalse(it.hasNext());
1382 // [start,end] fully contains 1 region and start of last
1383 // - 2 regions returned
1384 it = h.getBoundedStartIterator(3, 7, false);
1385 assertTrue(it.hasNext());
1387 assertEquals(3, next);
1389 assertEquals(6, next);
1390 assertFalse(it.hasNext());
1392 // [start,end] contains whole of last region
1393 // - 1 region returned
1394 it = h.getBoundedStartIterator(4, 20, false);
1395 assertTrue(it.hasNext());
1397 assertEquals(6, next);
1398 assertFalse(it.hasNext());