Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.datamodel

File HiddenColumnsTest.java

 

Code metrics

0
758
29
1
1,318
888
29
0.04
26.14
29
1

Classes

Class Line # Actions
HiddenColumnsTest 36 758 29
1.0100%
 

Contributing tests

This file is covered by 29 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.datamodel;
22   
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;
27   
28    import jalview.analysis.AlignmentGenerator;
29   
30    import java.util.Arrays;
31    import java.util.BitSet;
32    import java.util.Iterator;
33   
34    import org.testng.annotations.Test;
35   
 
36    public class HiddenColumnsTest
37    {
38    /**
39    * Test the method which counts the number of hidden columns
40    */
 
41  1 toggle @Test(groups = { "Functional" })
42    public void testGetSize()
43    {
44  1 HiddenColumns hidden = new HiddenColumns();
45  1 assertEquals(0, hidden.getSize());
46   
47  1 hidden.hideColumns(3, 5);
48  1 assertEquals(3, hidden.getSize());
49   
50  1 hidden.hideColumns(8, 8);
51  1 assertEquals(4, hidden.getSize());
52   
53  1 hidden.hideColumns(9, 14);
54  1 assertEquals(10, hidden.getSize());
55   
56  1 ColumnSelection cs = new ColumnSelection();
57  1 hidden.revealAllHiddenColumns(cs);
58  1 assertEquals(0, hidden.getSize());
59    }
60   
61    /**
62    * Test the method that finds the visible column position of an alignment
63    * column, allowing for hidden columns.
64    */
 
65  1 toggle @Test(groups = { "Functional" })
66    public void testFindColumnPosition()
67    {
68  1 HiddenColumns cs = new HiddenColumns();
69  1 assertEquals(5, cs.absoluteToVisibleColumn(5));
70   
71    // hiding column 6 makes no difference
72  1 cs.hideColumns(6, 6);
73  1 assertEquals(5, cs.absoluteToVisibleColumn(5));
74   
75    // hiding column 4 moves column 5 to column 4
76  1 cs.hideColumns(4, 4);
77  1 assertEquals(4, cs.absoluteToVisibleColumn(5));
78   
79    // hiding column 4 moves column 4 to position 3
80  1 assertEquals(3, cs.absoluteToVisibleColumn(4));
81   
82    // hiding columns 1 and 2 moves column 5 to column 2
83  1 cs.hideColumns(1, 2);
84  1 assertEquals(2, cs.absoluteToVisibleColumn(5));
85   
86    // check with > 1 hidden column regions
87    // where some columns are in the hidden regions
88  1 HiddenColumns cs2 = new HiddenColumns();
89  1 cs2.hideColumns(5, 10);
90  1 cs2.hideColumns(20, 27);
91  1 cs2.hideColumns(40, 44);
92   
93    // hiding columns 5-10 and 20-27 moves column 8 to column 4
94  1 assertEquals(4, cs2.absoluteToVisibleColumn(8));
95   
96    // and moves column 24 to 13
97  1 assertEquals(13, cs2.absoluteToVisibleColumn(24));
98   
99    // and moves column 28 to 14
100  1 assertEquals(14, cs2.absoluteToVisibleColumn(28));
101   
102    // and moves column 40 to 25
103  1 assertEquals(25, cs2.absoluteToVisibleColumn(40));
104   
105    // check when hidden columns start at 0 that the visible column
106    // is returned as 0
107  1 HiddenColumns cs3 = new HiddenColumns();
108  1 cs3.hideColumns(0, 4);
109  1 assertEquals(0, cs3.absoluteToVisibleColumn(2));
110   
111    // check that column after the last hidden region doesn't crash
112  1 assertEquals(46, cs2.absoluteToVisibleColumn(65));
113    }
114   
 
115  1 toggle @Test(groups = { "Functional" })
116    public void testVisibleContigsIterator()
117    {
118  1 HiddenColumns cs = new HiddenColumns();
119   
120  1 Iterator<int[]> visible = cs.getVisContigsIterator(3, 10, false);
121  1 int[] region = visible.next();
122  1 assertEquals("[3, 9]", Arrays.toString(region));
123  1 assertFalse(visible.hasNext());
124   
125  1 cs.hideColumns(3, 6);
126  1 cs.hideColumns(8, 9);
127  1 cs.hideColumns(12, 12);
128   
129    // Test both ends visible region
130   
131    // start position is inclusive, end position exclusive
132  1 visible = cs.getVisContigsIterator(1, 13, false);
133  1 region = visible.next();
134  1 assertEquals("[1, 2]", Arrays.toString(region));
135  1 region = visible.next();
136  1 assertEquals("[7, 7]", Arrays.toString(region));
137  1 region = visible.next();
138  1 assertEquals("[10, 11]", Arrays.toString(region));
139  1 assertFalse(visible.hasNext());
140   
141    // Test start hidden, end visible
142  1 visible = cs.getVisContigsIterator(4, 14, false);
143  1 region = visible.next();
144  1 assertEquals("[7, 7]", Arrays.toString(region));
145  1 region = visible.next();
146  1 assertEquals("[10, 11]", Arrays.toString(region));
147  1 region = visible.next();
148  1 assertEquals("[13, 13]", Arrays.toString(region));
149  1 assertFalse(visible.hasNext());
150   
151    // Test start hidden, end hidden
152  1 visible = cs.getVisContigsIterator(3, 10, false);
153  1 region = visible.next();
154  1 assertEquals("[7, 7]", Arrays.toString(region));
155  1 assertFalse(visible.hasNext());
156   
157    // Test start visible, end hidden
158  1 visible = cs.getVisContigsIterator(0, 13, false);
159  1 region = visible.next();
160  1 assertEquals("[0, 2]", Arrays.toString(region));
161  1 region = visible.next();
162  1 assertEquals("[7, 7]", Arrays.toString(region));
163  1 region = visible.next();
164  1 assertEquals("[10, 11]", Arrays.toString(region));
165  1 assertFalse(visible.hasNext());
166   
167    // Test empty result
168  1 visible = cs.getVisContigsIterator(4, 6, false);
169  1 assertFalse(visible.hasNext());
170    }
171   
 
172  1 toggle @Test(groups = { "Functional" })
173    public void testEquals()
174    {
175  1 HiddenColumns cs = new HiddenColumns();
176  1 cs.hideColumns(5, 9);
177   
178    // a different set of hidden columns
179  1 HiddenColumns cs2 = new HiddenColumns();
180   
181    // with no hidden columns
182  1 assertFalse(cs.equals(cs2));
183  1 assertFalse(cs2.equals(cs));
184   
185    // with the wrong kind of object
186  1 assertFalse(cs.equals(new HiddenColumnsCursor()));
187   
188    // with a different hiddenColumns object - by size
189  1 HiddenColumns cs3 = new HiddenColumns();
190  1 cs3.hideColumns(2, 3);
191  1 assertFalse(cs.equals(cs3));
192   
193    // with hidden columns added in a different order
194  1 cs2.hideColumns(6, 9);
195  1 assertFalse(cs.equals(cs2));
196  1 assertFalse(cs2.equals(cs));
197   
198  1 cs2.hideColumns(5, 8);
199   
200  1 assertTrue(cs.equals(cs2));
201  1 assertTrue(cs.equals(cs));
202  1 assertTrue(cs2.equals(cs));
203  1 assertTrue(cs2.equals(cs2));
204   
205    // different ranges, same size
206  1 cs.hideColumns(10, 12);
207  1 cs2.hideColumns(10, 15);
208  1 assertFalse(cs.equals(cs2));
209   
210    }
211   
 
212  1 toggle @Test(groups = "Functional")
213    public void testCopyConstructor()
214    {
215  1 HiddenColumns cs = new HiddenColumns();
216  1 cs.hideColumns(10, 11);
217  1 cs.hideColumns(5, 7);
218  1 Iterator<int[]> regions = cs.iterator();
219  1 assertEquals("[5, 7]", Arrays.toString(regions.next()));
220   
221  1 HiddenColumns cs2 = new HiddenColumns(cs);
222  1 regions = cs2.iterator();
223  1 assertTrue(cs2.hasHiddenColumns());
224  1 assertEquals(2, cs2.getNumberOfRegions());
225    // hidden columns are held in column order
226  1 assertEquals("[5, 7]", Arrays.toString(regions.next()));
227  1 assertEquals("[10, 11]", Arrays.toString(regions.next()));
228    }
229   
 
230  1 toggle @Test(groups = "Functional")
231    public void testCopyConstructor2()
232    {
233  1 HiddenColumns cs = new HiddenColumns();
234  1 cs.hideColumns(10, 11);
235  1 cs.hideColumns(5, 7);
236   
237  1 HiddenColumns cs2 = new HiddenColumns(cs, 3, 9, 1);
238  1 assertTrue(cs2.hasHiddenColumns());
239  1 Iterator<int[]> regions = cs2.iterator();
240   
241    // only [5,7] returned, offset by 1
242  1 assertEquals("[4, 6]", Arrays.toString(regions.next()));
243  1 assertEquals(3, cs2.getSize());
244   
245  1 cs2 = new HiddenColumns(cs, 8, 15, 4);
246  1 regions = cs2.iterator();
247  1 assertTrue(cs2.hasHiddenColumns());
248   
249    // only [10,11] returned, offset by 4
250  1 assertEquals("[6, 7]", Arrays.toString(regions.next()));
251  1 assertEquals(2, cs2.getSize());
252   
253  1 cs2 = new HiddenColumns(cs, 6, 10, 4);
254  1 assertFalse(cs2.hasHiddenColumns());
255    }
256   
 
257  1 toggle @Test(groups = { "Functional" })
258    public void testHideColumns()
259    {
260    // create random alignment
261  1 AlignmentGenerator gen = new AlignmentGenerator(false);
262  1 AlignmentI al = gen.generate(50, 20, 123, 5, 5);
263   
264  1 ColumnSelection colsel = new ColumnSelection();
265  1 HiddenColumns cs = al.getHiddenColumns();
266  1 colsel.hideSelectedColumns(5, al.getHiddenColumns());
267  1 Iterator<int[]> regions = cs.iterator();
268  1 assertEquals(1, cs.getNumberOfRegions());
269  1 assertEquals("[5, 5]", Arrays.toString(regions.next()));
270  1 assertEquals(cs.getSize(), 1);
271   
272  1 colsel.hideSelectedColumns(3, al.getHiddenColumns());
273  1 regions = cs.iterator();
274  1 assertEquals(2, cs.getNumberOfRegions());
275    // two hidden ranges, in order:
276  1 assertEquals("[3, 3]", Arrays.toString(regions.next()));
277  1 assertEquals("[5, 5]", Arrays.toString(regions.next()));
278  1 assertEquals(cs.getSize(), 2);
279   
280    // hiding column 4 expands [3, 3] to [3, 4]
281    // and merges to [5, 5] to make [3, 5]
282  1 colsel.hideSelectedColumns(4, al.getHiddenColumns());
283  1 regions = cs.iterator();
284  1 assertEquals(1, cs.getNumberOfRegions());
285  1 assertEquals("[3, 5]", Arrays.toString(regions.next()));
286  1 assertEquals(cs.getSize(), 3);
287   
288    // clear hidden columns (note they are added to selected)
289  1 cs.revealAllHiddenColumns(colsel);
290    // it is now actually null but getter returns an empty list
291  1 assertEquals(0, cs.getNumberOfRegions());
292  1 assertEquals(cs.getSize(), 0);
293   
294  1 cs.hideColumns(3, 6);
295  1 regions = cs.iterator();
296  1 int[] firstHiddenRange = regions.next();
297  1 assertEquals("[3, 6]", Arrays.toString(firstHiddenRange));
298  1 assertEquals(cs.getSize(), 4);
299   
300    // adding a subrange of already hidden should do nothing
301  1 cs.hideColumns(4, 5);
302  1 regions = cs.iterator();
303  1 assertEquals(1, cs.getNumberOfRegions());
304  1 assertEquals("[3, 6]", Arrays.toString(regions.next()));
305  1 assertEquals(cs.getSize(), 4);
306  1 cs.hideColumns(3, 5);
307  1 regions = cs.iterator();
308  1 assertEquals(1, cs.getNumberOfRegions());
309  1 assertEquals("[3, 6]", Arrays.toString(regions.next()));
310  1 assertEquals(cs.getSize(), 4);
311  1 cs.hideColumns(4, 6);
312  1 regions = cs.iterator();
313  1 assertEquals(1, cs.getNumberOfRegions());
314  1 assertEquals("[3, 6]", Arrays.toString(regions.next()));
315  1 assertEquals(cs.getSize(), 4);
316  1 cs.hideColumns(3, 6);
317  1 regions = cs.iterator();
318  1 assertEquals(1, cs.getNumberOfRegions());
319  1 assertEquals("[3, 6]", Arrays.toString(regions.next()));
320  1 assertEquals(cs.getSize(), 4);
321   
322  1 cs.revealAllHiddenColumns(colsel);
323  1 cs.hideColumns(2, 4);
324  1 regions = cs.iterator();
325  1 assertEquals(1, cs.getNumberOfRegions());
326  1 assertEquals("[2, 4]", Arrays.toString(regions.next()));
327  1 assertEquals(cs.getSize(), 3);
328   
329    // extend contiguous with 2 positions overlap
330  1 cs.hideColumns(3, 5);
331  1 regions = cs.iterator();
332  1 assertEquals(1, cs.getNumberOfRegions());
333  1 assertEquals("[2, 5]", Arrays.toString(regions.next()));
334  1 assertEquals(cs.getSize(), 4);
335   
336    // extend contiguous with 1 position overlap
337  1 cs.hideColumns(5, 6);
338  1 regions = cs.iterator();
339  1 assertEquals(1, cs.getNumberOfRegions());
340  1 assertEquals("[2, 6]", Arrays.toString(regions.next()));
341  1 assertEquals(cs.getSize(), 5);
342   
343    // extend contiguous with overlap both ends:
344  1 cs.hideColumns(1, 7);
345  1 regions = cs.iterator();
346  1 assertEquals(1, cs.getNumberOfRegions());
347  1 assertEquals("[1, 7]", Arrays.toString(regions.next()));
348  1 assertEquals(cs.getSize(), 7);
349   
350  1 cs.revealAllHiddenColumns(colsel);
351  1 cs.hideColumns(15, 18);
352  1 cs.hideColumns(2, 4);
353  1 cs.hideColumns(7, 9);
354  1 regions = cs.iterator();
355  1 assertEquals(3, cs.getNumberOfRegions());
356  1 assertEquals("[2, 4]", Arrays.toString(regions.next()));
357  1 assertEquals("[7, 9]", Arrays.toString(regions.next()));
358  1 assertEquals("[15, 18]", Arrays.toString(regions.next()));
359  1 assertEquals(cs.getSize(), 10);
360    }
361   
362    /**
363    * Test the method that reveals a range of hidden columns given the start
364    * column of the range
365    */
 
366  1 toggle @Test(groups = { "Functional" })
367    public void testRevealHiddenColumns()
368    {
369  1 ColumnSelection colsel = new ColumnSelection();
370  1 HiddenColumns cs = new HiddenColumns();
371   
372    // test with null hidden columns
373  1 cs.revealHiddenColumns(5, colsel);
374  1 assertTrue(colsel.getSelected().isEmpty());
375   
376  1 cs.hideColumns(5, 8);
377  1 colsel.addElement(10);
378  1 cs.revealHiddenColumns(5, colsel);
379   
380    // hiddenColumns now empty
381  1 assertEquals(0, cs.getSize());
382   
383    // revealed columns are marked as selected (added to selection):
384  1 assertEquals("[10, 5, 6, 7, 8]", colsel.getSelected().toString());
385   
386    // calling with a column other than the range start does nothing:
387  1 colsel = new ColumnSelection();
388  1 cs = new HiddenColumns();
389  1 cs.hideColumns(5, 8);
390   
391  1 int prevSize = cs.getSize();
392  1 cs.revealHiddenColumns(6, colsel);
393  1 assertEquals(prevSize, cs.getSize());
394  1 assertTrue(colsel.getSelected().isEmpty());
395   
396    // reveal hidden columns when there is more than one region
397  1 cs.hideColumns(20, 23);
398    // now there are 2 hidden regions
399  1 assertEquals(2, cs.getNumberOfRegions());
400   
401  1 cs.revealHiddenColumns(20, colsel);
402   
403    // hiddenColumns now has one region
404  1 assertEquals(1, cs.getNumberOfRegions());
405   
406    // revealed columns are marked as selected (added to selection):
407  1 assertEquals("[20, 21, 22, 23]", colsel.getSelected().toString());
408   
409    // call with a column past the end of the hidden column ranges
410  1 colsel.clear();
411  1 cs.revealHiddenColumns(20, colsel);
412    // hiddenColumns still has 1 region
413  1 assertEquals(1, cs.getNumberOfRegions());
414  1 assertTrue(colsel.getSelected().isEmpty());
415    }
416   
 
417  1 toggle @Test(groups = { "Functional" })
418    public void testRevealAllHiddenColumns()
419    {
420  1 HiddenColumns hidden = new HiddenColumns();
421  1 ColumnSelection colsel = new ColumnSelection();
422   
423    // test with null hidden columns
424  1 hidden.revealAllHiddenColumns(colsel);
425  1 assertTrue(colsel.getSelected().isEmpty());
426   
427  1 hidden.hideColumns(5, 8);
428  1 hidden.hideColumns(2, 3);
429  1 colsel.addElement(11);
430  1 colsel.addElement(1);
431  1 hidden.revealAllHiddenColumns(colsel);
432   
433    /*
434    * revealing hidden columns adds them (in order) to the (unordered)
435    * selection list
436    */
437   
438    // hiddenColumns now empty
439  1 assertEquals(0, hidden.getSize());
440   
441  1 assertEquals("[11, 1, 2, 3, 5, 6, 7, 8]",
442    colsel.getSelected().toString());
443    }
444   
 
445  1 toggle @Test(groups = { "Functional" })
446    public void testIsVisible()
447    {
448  1 HiddenColumns cs = new HiddenColumns();
449  1 assertTrue(cs.isVisible(5));
450   
451  1 cs.hideColumns(2, 4);
452  1 cs.hideColumns(6, 7);
453  1 assertTrue(cs.isVisible(0));
454  1 assertTrue(cs.isVisible(-99));
455  1 assertTrue(cs.isVisible(1));
456  1 assertFalse(cs.isVisible(2));
457  1 assertFalse(cs.isVisible(3));
458  1 assertFalse(cs.isVisible(4));
459  1 assertTrue(cs.isVisible(5));
460  1 assertFalse(cs.isVisible(6));
461  1 assertFalse(cs.isVisible(7));
462  1 assertTrue(cs.isVisible(8));
463    }
464   
465    /**
466    * Test for the case when a hidden range encloses more one already hidden
467    * range
468    */
 
469  1 toggle @Test(groups = { "Functional" })
470    public void testHideColumns_subsumingHidden()
471    {
472    /*
473    * JAL-2370 bug scenario:
474    * two hidden ranges subsumed by a third
475    */
476  1 HiddenColumns cs = new HiddenColumns();
477  1 cs.hideColumns(49, 59);
478  1 cs.hideColumns(69, 79);
479  1 Iterator<int[]> regions = cs.iterator();
480  1 assertEquals(2, cs.getNumberOfRegions());
481  1 assertEquals("[49, 59]", Arrays.toString(regions.next()));
482  1 assertEquals("[69, 79]", Arrays.toString(regions.next()));
483  1 assertEquals(22, cs.getSize());
484   
485  1 cs.hideColumns(48, 80);
486  1 regions = cs.iterator();
487  1 assertEquals(1, cs.getNumberOfRegions());
488  1 assertEquals("[48, 80]", Arrays.toString(regions.next()));
489  1 assertEquals(33, cs.getSize());
490   
491    /*
492    * another...joining hidden ranges
493    */
494  1 cs = new HiddenColumns();
495  1 cs.hideColumns(10, 20);
496  1 cs.hideColumns(30, 40);
497  1 cs.hideColumns(50, 60);
498    // hiding 21-49 should merge to one range
499  1 cs.hideColumns(21, 49);
500  1 regions = cs.iterator();
501  1 assertEquals(1, cs.getNumberOfRegions());
502  1 assertEquals("[10, 60]", Arrays.toString(regions.next()));
503  1 assertEquals(51, cs.getSize());
504   
505    /*
506    * another...left overlap, subsumption, right overlap,
507    * no overlap of existing hidden ranges
508    */
509  1 cs = new HiddenColumns();
510  1 cs.hideColumns(10, 20);
511  1 cs.hideColumns(10, 20);
512  1 cs.hideColumns(30, 35);
513  1 cs.hideColumns(40, 50);
514  1 cs.hideColumns(60, 70);
515   
516  1 cs.hideColumns(15, 45);
517  1 regions = cs.iterator();
518  1 assertEquals(2, cs.getNumberOfRegions());
519  1 assertEquals("[10, 50]", Arrays.toString(regions.next()));
520  1 assertEquals("[60, 70]", Arrays.toString(regions.next()));
521  1 assertEquals(52, cs.getSize());
522    }
523   
 
524  1 toggle @Test(groups = { "Functional" })
525    public void testHideColumns_BitSet()
526    {
527  1 HiddenColumns cs;
528   
529  1 BitSet one = new BitSet();
530   
531    // one hidden range
532  1 one.set(1);
533  1 cs = new HiddenColumns();
534  1 cs.hideColumns(one);
535  1 assertEquals(1, cs.getNumberOfRegions());
536  1 assertEquals(1, cs.getSize());
537   
538  1 one.set(2);
539  1 cs = new HiddenColumns();
540  1 cs.hideColumns(one);
541  1 assertEquals(1, cs.getNumberOfRegions());
542  1 assertEquals(2, cs.getSize());
543   
544  1 one.set(3);
545  1 cs = new HiddenColumns();
546  1 cs.hideColumns(one);
547  1 assertEquals(1, cs.getNumberOfRegions());
548  1 assertEquals(3, cs.getSize());
549   
550    // split
551  1 one.clear(2);
552  1 cs = new HiddenColumns();
553  1 cs.hideColumns(one);
554  1 assertEquals(2, cs.getNumberOfRegions());
555  1 assertEquals(2, cs.getSize());
556   
557  1 assertEquals(0, cs.visibleToAbsoluteColumn(0));
558  1 assertEquals(2, cs.visibleToAbsoluteColumn(1));
559  1 assertEquals(4, cs.visibleToAbsoluteColumn(2));
560   
561    // one again
562  1 one.clear(1);
563  1 cs = new HiddenColumns();
564  1 cs.hideColumns(one);
565  1 assertEquals(1, cs.getSize());
566   
567  1 assertEquals(1, cs.getNumberOfRegions());
568   
569  1 assertEquals(0, cs.visibleToAbsoluteColumn(0));
570  1 assertEquals(1, cs.visibleToAbsoluteColumn(1));
571  1 assertEquals(2, cs.visibleToAbsoluteColumn(2));
572  1 assertEquals(4, cs.visibleToAbsoluteColumn(3));
573    }
574   
 
575  1 toggle @Test(groups = { "Functional" })
576    public void testRegionsToString()
577    {
578  1 HiddenColumns hc = new HiddenColumns();
579   
580  1 String result = hc.regionsToString(",", "--");
581  1 assertEquals("", result);
582   
583  1 hc.hideColumns(3, 7);
584  1 hc.hideColumns(10, 10);
585  1 hc.hideColumns(14, 15);
586   
587  1 result = hc.regionsToString(",", "--");
588  1 assertEquals("3--7,10--10,14--15", result);
589    }
590   
 
591  1 toggle @Test(groups = "Functional")
592    public void testGetVisibleStartAndEndIndex()
593    {
594  1 Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
595  1 AlignmentI align = new Alignment(new SequenceI[] { seq });
596  1 HiddenColumns hc = new HiddenColumns();
597   
598  1 int[] startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
599  1 assertEquals(0, startEnd[0]);
600  1 assertEquals(25, startEnd[1]);
601   
602  1 hc.hideColumns(0, 0);
603  1 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
604  1 assertEquals(1, startEnd[0]);
605  1 assertEquals(25, startEnd[1]);
606   
607  1 hc.hideColumns(6, 9);
608  1 hc.hideColumns(11, 12);
609  1 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
610  1 assertEquals(1, startEnd[0]);
611  1 assertEquals(25, startEnd[1]);
612   
613  1 hc.hideColumns(24, 25);
614  1 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
615  1 System.out.println(startEnd[0] + " : " + startEnd[1]);
616  1 assertEquals(1, startEnd[0]);
617  1 assertEquals(23, startEnd[1]);
618   
619    // force lowest range to start of alignment
620  1 hc = new HiddenColumns();
621  1 hc.hideColumns(3, 4);
622  1 startEnd = hc.getVisibleStartAndEndIndex(align.getWidth());
623  1 assertEquals(0, startEnd[0]);
624  1 assertEquals(25, startEnd[1]);
625    }
626   
 
627  1 toggle @Test(groups = "Functional")
628    public void testGetRegionWithEdgeAtRes()
629    {
630  1 HiddenColumns hc = new HiddenColumns();
631   
632  1 int[] result = hc.getRegionWithEdgeAtRes(5);
633  1 assertNull(result);
634   
635  1 hc.hideColumns(3, 7);
636  1 hc.hideColumns(10, 10);
637  1 hc.hideColumns(14, 15);
638   
639  1 result = hc.getRegionWithEdgeAtRes(2);
640  1 assertEquals(3, result[0]);
641  1 assertEquals(7, result[1]);
642   
643  1 result = hc.getRegionWithEdgeAtRes(4);
644  1 assertEquals(10, result[0]);
645  1 assertEquals(10, result[1]);
646   
647  1 result = hc.getRegionWithEdgeAtRes(5);
648  1 assertEquals(10, result[0]);
649  1 assertEquals(10, result[1]);
650   
651  1 result = hc.getRegionWithEdgeAtRes(6);
652  1 assertNull(result);
653   
654  1 result = hc.getRegionWithEdgeAtRes(0);
655  1 assertNull(result);
656   
657  1 result = hc.getRegionWithEdgeAtRes(7);
658  1 assertEquals(14, result[0]);
659  1 assertEquals(15, result[1]);
660   
661  1 result = hc.getRegionWithEdgeAtRes(8);
662  1 assertEquals(14, result[0]);
663  1 assertEquals(15, result[1]);
664   
665  1 result = hc.getRegionWithEdgeAtRes(16);
666  1 assertNull(result);
667    }
668   
 
669  1 toggle @Test(groups = "Functional")
670    public void testHasHiddenColumns()
671    {
672  1 HiddenColumns h = new HiddenColumns();
673   
674    // new HiddenColumns2 has no hidden cols
675  1 assertFalse(h.hasHiddenColumns());
676   
677    // some columns hidden, returns true
678  1 h.hideColumns(5, 10);
679  1 assertTrue(h.hasHiddenColumns());
680   
681    // reveal columns, no hidden cols again
682  1 ColumnSelection sel = new ColumnSelection();
683  1 h.revealAllHiddenColumns(sel);
684  1 assertFalse(h.hasHiddenColumns());
685    }
686   
 
687  1 toggle @Test(groups = "Functional")
688    public void testHasManyHiddenColumns()
689    {
690  1 HiddenColumns h = new HiddenColumns();
691   
692    // h has no hidden cols
693  1 assertFalse(h.hasMultiHiddenColumnRegions());
694   
695    // one set of columns hidden, returns false
696  1 h.hideColumns(5, 10);
697  1 assertFalse(h.hasMultiHiddenColumnRegions());
698   
699    // two sets hidden, returns true
700  1 h.hideColumns(15, 17);
701  1 assertTrue(h.hasMultiHiddenColumnRegions());
702   
703    // back to one block, asserts false
704  1 h.hideColumns(11, 14);
705  1 assertFalse(h.hasMultiHiddenColumnRegions());
706    }
707   
 
708  1 toggle @Test(groups = "Functional")
709    public void testAdjustForHiddenColumns()
710    {
711  1 HiddenColumns h = new HiddenColumns();
712    // returns input value when there are no hidden columns
713  1 assertEquals(10, h.visibleToAbsoluteColumn(10));
714   
715  1 h.hideColumns(20, 30);
716  1 assertEquals(10, h.visibleToAbsoluteColumn(10));
717  1 assertEquals(20 + 11, h.visibleToAbsoluteColumn(20));
718  1 assertEquals(35 + 11, h.visibleToAbsoluteColumn(35));
719   
720  1 h.hideColumns(5, 7);
721  1 assertEquals(10 + 3, h.visibleToAbsoluteColumn(10));
722  1 assertEquals(20 + 14, h.visibleToAbsoluteColumn(20));
723  1 assertEquals(35 + 14, h.visibleToAbsoluteColumn(35));
724   
725  1 ColumnSelection sel = new ColumnSelection();
726  1 h.revealAllHiddenColumns(sel);
727  1 h.hideColumns(0, 1);
728  1 assertEquals(4, h.visibleToAbsoluteColumn(2));
729    }
730   
 
731  1 toggle @Test(groups = "Functional")
732    public void testGetNextHiddenBoundary_Left()
733    {
734  1 HiddenColumns h = new HiddenColumns();
735   
736    // returns same value if no hidden cols
737  1 assertEquals(3, h.getNextHiddenBoundary(true, 3));
738   
739  1 h.hideColumns(5, 10);
740  1 assertEquals(10, h.getNextHiddenBoundary(true, 15));
741  1 assertEquals(3, h.getNextHiddenBoundary(true, 3));
742  1 assertEquals(7, h.getNextHiddenBoundary(true, 7));
743   
744  1 h.hideColumns(15, 20);
745  1 assertEquals(10, h.getNextHiddenBoundary(true, 15));
746  1 assertEquals(20, h.getNextHiddenBoundary(true, 21));
747    }
748   
 
749  1 toggle @Test(groups = "Functional")
750    public void testGetNextHiddenBoundary_Right()
751    {
752  1 HiddenColumns h = new HiddenColumns();
753   
754    // returns same value if no hidden cols
755  1 assertEquals(3, h.getNextHiddenBoundary(false, 3));
756   
757  1 h.hideColumns(5, 10);
758  1 assertEquals(5, h.getNextHiddenBoundary(false, 3));
759  1 assertEquals(15, h.getNextHiddenBoundary(false, 15));
760  1 assertEquals(7, h.getNextHiddenBoundary(false, 7));
761   
762  1 h.hideColumns(15, 20);
763  1 assertEquals(15, h.getNextHiddenBoundary(false, 7));
764  1 assertEquals(15, h.getNextHiddenBoundary(false, 14));
765   
766    // returns same value if there is no next hidden column
767  1 assertEquals(22, h.getNextHiddenBoundary(false, 22));
768    }
769   
 
770  1 toggle @Test(groups = "Functional")
771    public void testIterator()
772    {
773  1 HiddenColumns h = new HiddenColumns();
774  1 Iterator<int[]> result = h.iterator();
775  1 assertFalse(result.hasNext());
776   
777  1 h.hideColumns(5, 10);
778  1 result = h.iterator();
779  1 int[] next = result.next();
780  1 assertEquals(5, next[0]);
781  1 assertEquals(10, next[1]);
782  1 assertFalse(result.hasNext());
783   
784  1 h.hideColumns(22, 23);
785  1 result = h.iterator();
786  1 next = result.next();
787  1 assertEquals(5, next[0]);
788  1 assertEquals(10, next[1]);
789  1 next = result.next();
790  1 assertEquals(22, next[0]);
791  1 assertEquals(23, next[1]);
792  1 assertFalse(result.hasNext());
793   
794    // test for only one hidden region at start of alignment
795  1 ColumnSelection sel = new ColumnSelection();
796  1 h.revealAllHiddenColumns(sel);
797  1 h.hideColumns(0, 1);
798  1 result = h.iterator();
799  1 next = result.next();
800  1 assertEquals(0, next[0]);
801  1 assertEquals(1, next[1]);
802  1 assertFalse(result.hasNext());
803    }
804   
805    /* @Test(groups = "Functional")
806    public void testGetVisibleSequenceStrings()
807    {
808    HiddenColumns h = new HiddenColumns();
809    SequenceI seq1 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
810    SequenceI seq2 = new Sequence("TEST2", "VICYHRNDTGA");
811    SequenceI[] seqs = new SequenceI[2];
812    seqs[0] = seq1;
813    seqs[1] = seq2;
814    String[] result = h.getVisibleSequenceStrings(5, 10, seqs);
815    assertEquals(2, result.length);
816    assertEquals("WKQES", result[0]);
817    assertEquals("RNDTG", result[1]);
818   
819    h.hideColumns(6, 8);
820    result = h.getVisibleSequenceStrings(5, 10, seqs);
821    assertEquals(2, result.length);
822    assertEquals("WS", result[0]);
823    assertEquals("RG", result[1]);
824   
825    SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
826    ColumnSelection sel = new ColumnSelection();
827    h.revealAllHiddenColumns(sel);
828    h.hideColumns(1, 3);
829    h.hideColumns(6, 11);
830    assertEquals("-D",
831    h.getVisibleSequenceStrings(0, 5, new SequenceI[]
832    { seq })[0]);
833    }*/
834   
 
835  1 toggle @Test(groups = "Functional")
836    public void testHideInsertionsFor()
837    {
838  1 HiddenColumns h = new HiddenColumns();
839  1 HiddenColumns h2 = new HiddenColumns();
840  1 SequenceI seq1 = new Sequence("TEST1", "GAL---MFW-KQESPVICY--HRNDT");
841  1 SequenceI seq2 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
842   
843  1 h.hideList(seq2.getInsertions());
844  1 assertTrue(h.equals(h2));
845  1 assertEquals(0, h.getSize());
846   
847  1 h.hideList(seq1.getInsertions());
848  1 h2.hideColumns(3, 5);
849  1 h2.hideColumns(9, 9);
850  1 h2.hideColumns(19, 20);
851  1 assertTrue(h.equals(h2));
852  1 assertEquals(6, h.getSize());
853    }
854   
 
855  1 toggle @Test(groups = "Functional")
856    public void testHideColumns_BitSet_range()
857    {
858  1 HiddenColumns h = new HiddenColumns();
859  1 HiddenColumns h2 = new HiddenColumns();
860   
861  1 BitSet tohide = new BitSet(25);
862  1 h.hideColumns(tohide);
863  1 assertTrue(h.equals(h2));
864   
865    // when setting bitset, first param is inclusive, second exclusive
866  1 tohide.set(3, 6);
867  1 tohide.set(9);
868  1 tohide.set(15, 21);
869  1 h.clearAndHideColumns(tohide, 5, 23);
870   
871  1 h2.hideColumns(5, 5);
872  1 h2.hideColumns(9, 9);
873  1 h2.hideColumns(15, 20);
874  1 assertTrue(h.equals(h2));
875  1 assertEquals(h.getSize(), h2.getSize());
876   
877  1 tohide.clear();
878  1 tohide.set(41);
879  1 h.clearAndHideColumns(tohide, 23, 30);
880  1 assertTrue(h.equals(h2));
881  1 assertEquals(h.getSize(), h2.getSize());
882   
883  1 tohide.set(41);
884  1 h.clearAndHideColumns(tohide, 30, 45);
885  1 h2.hideColumns(41, 41);
886  1 assertTrue(h.equals(h2));
887  1 assertEquals(h.getSize(), h2.getSize());
888   
889  1 tohide.clear();
890  1 tohide.set(25, 28);
891  1 h.clearAndHideColumns(tohide, 17, 50);
892  1 h2 = new HiddenColumns();
893  1 h2.hideColumns(5, 5);
894  1 h2.hideColumns(9, 9);
895  1 h2.hideColumns(15, 16);
896  1 h2.hideColumns(25, 27);
897  1 assertTrue(h.equals(h2));
898  1 assertEquals(h.getSize(), h2.getSize());
899   
900  1 HiddenColumns hc = new HiddenColumns();
901  1 hc.hideColumns(3, 5);
902  1 hc.hideColumns(15, 20);
903  1 hc.hideColumns(45, 60);
904   
905  1 tohide = new BitSet();
906   
907    // all unhidden if tohide is empty and range covers hidden
908  1 hc.clearAndHideColumns(tohide, 1, 70);
909  1 assertTrue(!hc.hasHiddenColumns());
910  1 assertEquals(0, hc.getSize());
911   
912  1 hc.hideColumns(3, 5);
913  1 hc.hideColumns(15, 20);
914  1 hc.hideColumns(45, 60);
915  1 assertEquals(25, hc.getSize());
916   
917    // but not if range does not cover hidden
918  1 hc.clearAndHideColumns(tohide, 23, 40);
919  1 assertTrue(hc.hasHiddenColumns());
920  1 assertEquals(25, hc.getSize());
921   
922    // and partial unhide if range partially covers
923  1 hc.clearAndHideColumns(tohide, 1, 17);
924  1 Iterator<int[]> it = hc.iterator();
925  1 assertTrue(it.hasNext());
926  1 int[] region = it.next();
927   
928  1 assertEquals(18, region[0]);
929  1 assertEquals(20, region[1]);
930   
931  1 assertTrue(it.hasNext());
932  1 region = it.next();
933   
934  1 assertEquals(45, region[0]);
935  1 assertEquals(60, region[1]);
936   
937  1 assertFalse(it.hasNext());
938  1 assertEquals(19, hc.getSize());
939    }
940   
 
941  1 toggle @Test(groups = "Functional")
942    public void testOffsetByVisibleColumns()
943    {
944  1 HiddenColumns h = new HiddenColumns();
945  1 int result = h.offsetByVisibleColumns(-1, 10);
946  1 assertEquals(9, result);
947   
948  1 h.hideColumns(7, 9);
949  1 result = h.offsetByVisibleColumns(-4, 10);
950  1 assertEquals(3, result);
951   
952  1 h.hideColumns(14, 15);
953  1 result = h.offsetByVisibleColumns(-4, 10);
954  1 assertEquals(3, result);
955   
956  1 result = h.offsetByVisibleColumns(-10, 17);
957  1 assertEquals(2, result);
958   
959  1 result = h.offsetByVisibleColumns(-1, 7);
960  1 assertEquals(5, result);
961   
962  1 result = h.offsetByVisibleColumns(-1, 8);
963  1 assertEquals(5, result);
964   
965  1 result = h.offsetByVisibleColumns(-3, 15);
966  1 assertEquals(10, result);
967   
968  1 ColumnSelection sel = new ColumnSelection();
969  1 h.revealAllHiddenColumns(sel);
970  1 h.hideColumns(0, 30);
971  1 result = h.offsetByVisibleColumns(-31, 0);
972  1 assertEquals(-31, result);
973   
974  1 HiddenColumns cs = new HiddenColumns();
975   
976    // test that without hidden columns, offsetByVisibleColumns returns
977    // position n to left of provided position
978  1 long pos = cs.offsetByVisibleColumns(-3, 10);
979  1 assertEquals(7, pos);
980   
981    // 0 returns same position
982  1 pos = cs.offsetByVisibleColumns(0, 10);
983  1 assertEquals(10, pos);
984   
985    // overflow to left returns negative number
986  1 pos = cs.offsetByVisibleColumns(-3, 0);
987  1 assertEquals(-3, pos);
988   
989    // test that with hidden columns to left of result column
990    // behaviour is the same as above
991  1 cs.hideColumns(1, 3);
992   
993    // position n to left of provided position
994  1 pos = cs.offsetByVisibleColumns(-3, 10);
995  1 assertEquals(7, pos);
996   
997    // 0 returns same position
998  1 pos = cs.offsetByVisibleColumns(0, 10);
999  1 assertEquals(10, pos);
1000   
1001    // test with one set of hidden columns between start and required position
1002  1 cs.hideColumns(12, 15);
1003  1 pos = cs.offsetByVisibleColumns(-8, 17);
1004  1 assertEquals(5, pos);
1005   
1006    // test with two sets of hidden columns between start and required position
1007  1 cs.hideColumns(20, 21);
1008  1 pos = cs.offsetByVisibleColumns(-8, 23);
1009  1 assertEquals(9, pos);
1010   
1011    // repeat last 2 tests with no hidden columns to left of required position
1012  1 ColumnSelection colsel = new ColumnSelection();
1013  1 cs.revealAllHiddenColumns(colsel);
1014   
1015    // test with one set of hidden columns between start and required position
1016  1 cs.hideColumns(12, 15);
1017  1 pos = cs.offsetByVisibleColumns(-8, 17);
1018  1 assertEquals(5, pos);
1019   
1020    // test with two sets of hidden columns between start and required position
1021  1 cs.hideColumns(20, 21);
1022  1 pos = cs.offsetByVisibleColumns(-8, 23);
1023  1 assertEquals(9, pos);
1024   
1025    // test with right (positive) offsets
1026   
1027    // test that without hidden columns, offsetByVisibleColumns returns
1028    // position n to right of provided position
1029  1 pos = cs.offsetByVisibleColumns(3, 7);
1030  1 assertEquals(10, pos);
1031   
1032    // test that with hidden columns to left of result column
1033    // behaviour is the same as above
1034  1 cs.hideColumns(1, 3);
1035   
1036    // test with one set of hidden columns between start and required position
1037  1 cs.hideColumns(12, 15);
1038  1 pos = cs.offsetByVisibleColumns(8, 5);
1039  1 assertEquals(17, pos);
1040   
1041    // test with two sets of hidden columns between start and required position
1042  1 cs.hideColumns(20, 21);
1043  1 pos = cs.offsetByVisibleColumns(8, 9);
1044  1 assertEquals(23, pos);
1045   
1046    // repeat last 2 tests with no hidden columns to left of required position
1047  1 colsel = new ColumnSelection();
1048  1 cs.revealAllHiddenColumns(colsel);
1049   
1050    // test with one set of hidden columns between start and required position
1051  1 cs.hideColumns(12, 15);
1052  1 pos = cs.offsetByVisibleColumns(8, 5);
1053  1 assertEquals(17, pos);
1054   
1055    // test with two sets of hidden columns between start and required position
1056  1 cs.hideColumns(20, 21);
1057  1 pos = cs.offsetByVisibleColumns(8, 9);
1058  1 assertEquals(23, pos);
1059    }
1060   
 
1061  1 toggle @Test(groups = "Functional")
1062    public void testBoundedIterator()
1063    {
1064  1 HiddenColumns h = new HiddenColumns();
1065  1 Iterator<int[]> it = h.getBoundedIterator(0, 10);
1066   
1067    // no hidden columns = nothing to iterate over
1068  1 assertFalse(it.hasNext());
1069   
1070    // [start,end] contains all hidden columns
1071    // all regions are returned
1072  1 h.hideColumns(3, 10);
1073  1 h.hideColumns(14, 16);
1074  1 it = h.getBoundedIterator(0, 20);
1075  1 assertTrue(it.hasNext());
1076  1 int[] next = it.next();
1077  1 assertEquals(3, next[0]);
1078  1 assertEquals(10, next[1]);
1079  1 next = it.next();
1080  1 assertEquals(14, next[0]);
1081  1 assertEquals(16, next[1]);
1082  1 assertFalse(it.hasNext());
1083   
1084    // [start,end] overlaps a region
1085    // 1 region returned
1086  1 it = h.getBoundedIterator(5, 7);
1087  1 assertTrue(it.hasNext());
1088  1 next = it.next();
1089  1 assertEquals(3, next[0]);
1090  1 assertEquals(10, next[1]);
1091  1 assertFalse(it.hasNext());
1092   
1093    // [start,end] fully contains 1 region and start of last
1094    // - 2 regions returned
1095  1 it = h.getBoundedIterator(3, 15);
1096  1 assertTrue(it.hasNext());
1097  1 next = it.next();
1098  1 assertEquals(3, next[0]);
1099  1 assertEquals(10, next[1]);
1100  1 next = it.next();
1101  1 assertEquals(14, next[0]);
1102  1 assertEquals(16, next[1]);
1103  1 assertFalse(it.hasNext());
1104   
1105    // [start,end] contains end of first region and whole of last region
1106    // - 2 regions returned
1107  1 it = h.getBoundedIterator(4, 20);
1108  1 assertTrue(it.hasNext());
1109  1 next = it.next();
1110  1 assertEquals(3, next[0]);
1111  1 assertEquals(10, next[1]);
1112  1 next = it.next();
1113  1 assertEquals(14, next[0]);
1114  1 assertEquals(16, next[1]);
1115  1 assertFalse(it.hasNext());
1116    }
1117   
 
1118  1 toggle @Test(groups = "Functional")
1119    public void testBoundedStartIterator()
1120    {
1121  1 HiddenColumns h = new HiddenColumns();
1122  1 Iterator<Integer> it = h.getStartRegionIterator(0, 10);
1123   
1124    // no hidden columns = nothing to iterate over
1125  1 assertFalse(it.hasNext());
1126   
1127    // [start,end] contains all hidden columns
1128    // all regions are returned
1129  1 h.hideColumns(3, 10);
1130  1 h.hideColumns(14, 16);
1131  1 it = h.getStartRegionIterator(0, 20);
1132  1 assertTrue(it.hasNext());
1133  1 int next = it.next();
1134  1 assertEquals(3, next);
1135  1 next = it.next();
1136  1 assertEquals(6, next);
1137  1 assertFalse(it.hasNext());
1138   
1139    // [start,end] does not contain a start of a region
1140    // no regions to iterate over
1141  1 it = h.getStartRegionIterator(4, 5);
1142  1 assertFalse(it.hasNext());
1143   
1144    // [start,end] fully contains 1 region and start of last
1145    // - 2 regions returned
1146  1 it = h.getStartRegionIterator(3, 7);
1147  1 assertTrue(it.hasNext());
1148  1 next = it.next();
1149  1 assertEquals(3, next);
1150  1 next = it.next();
1151  1 assertEquals(6, next);
1152  1 assertFalse(it.hasNext());
1153   
1154    // [start,end] contains whole of last region
1155    // - 1 region returned
1156  1 it = h.getStartRegionIterator(4, 20);
1157  1 assertTrue(it.hasNext());
1158  1 next = it.next();
1159  1 assertEquals(6, next);
1160  1 assertFalse(it.hasNext());
1161    }
1162   
 
1163  1 toggle @Test(groups = "Functional")
1164    public void testVisibleBlocksVisBoundsIterator()
1165    {
1166  1 HiddenColumns h = new HiddenColumns();
1167  1 Iterator<int[]> regions = h.getVisContigsIterator(0, 31, true);
1168   
1169    // only 1 visible region spanning 0-30 if nothing is hidden
1170  1 assertTrue(regions.hasNext());
1171  1 int[] region = regions.next();
1172  1 assertEquals(0, region[0]);
1173  1 assertEquals(30, region[1]);
1174  1 assertFalse(regions.hasNext());
1175   
1176    // hide 1 region in middle
1177    // 2 regions one on either side
1178    // second region boundary accounts for hidden columns
1179  1 h.hideColumns(10, 15);
1180  1 regions = h.getVisContigsIterator(0, 31, true);
1181   
1182  1 assertTrue(regions.hasNext());
1183  1 region = regions.next();
1184  1 assertEquals(0, region[0]);
1185  1 assertEquals(9, region[1]);
1186  1 region = regions.next();
1187  1 assertEquals(16, region[0]);
1188  1 assertEquals(36, region[1]);
1189  1 assertFalse(regions.hasNext());
1190   
1191    // single hidden region at left
1192  1 h = new HiddenColumns();
1193  1 h.hideColumns(0, 5);
1194  1 regions = h.getVisContigsIterator(0, 31, true);
1195   
1196  1 assertTrue(regions.hasNext());
1197  1 region = regions.next();
1198  1 assertEquals(6, region[0]);
1199  1 assertEquals(36, region[1]);
1200  1 assertFalse(regions.hasNext());
1201   
1202    // single hidden region at right
1203  1 h = new HiddenColumns();
1204  1 h.hideColumns(27, 30);
1205  1 regions = h.getVisContigsIterator(0, 31, true);
1206   
1207  1 assertTrue(regions.hasNext());
1208  1 region = regions.next();
1209  1 assertEquals(0, region[0]);
1210  1 assertEquals(26, region[1]);
1211  1 region = regions.next();
1212  1 assertEquals(31, region[0]);
1213  1 assertEquals(34, region[1]);
1214  1 assertFalse(regions.hasNext());
1215   
1216    // hidden region at left + hidden region in middle
1217  1 h = new HiddenColumns();
1218  1 h.hideColumns(0, 5);
1219  1 h.hideColumns(23, 25);
1220  1 regions = h.getVisContigsIterator(0, 31, true);
1221   
1222  1 assertTrue(regions.hasNext());
1223  1 region = regions.next();
1224  1 assertEquals(6, region[0]);
1225  1 assertEquals(22, region[1]);
1226  1 region = regions.next();
1227  1 assertEquals(26, region[0]);
1228  1 assertEquals(39, region[1]);
1229  1 assertFalse(regions.hasNext());
1230   
1231    // hidden region at right + hidden region in middle
1232  1 h = new HiddenColumns();
1233  1 h.hideColumns(27, 30);
1234  1 h.hideColumns(11, 14);
1235  1 regions = h.getVisContigsIterator(0, 31, true);
1236   
1237  1 assertTrue(regions.hasNext());
1238  1 region = regions.next();
1239  1 assertEquals(0, region[0]);
1240  1 assertEquals(10, region[1]);
1241  1 region = regions.next();
1242  1 assertEquals(15, region[0]);
1243  1 assertEquals(26, region[1]);
1244  1 region = regions.next();
1245  1 assertEquals(31, region[0]);
1246  1 assertEquals(38, region[1]);
1247  1 assertFalse(regions.hasNext());
1248   
1249    // hidden region at left and right
1250  1 h = new HiddenColumns();
1251  1 h.hideColumns(27, 35);
1252  1 h.hideColumns(0, 4);
1253  1 regions = h.getVisContigsIterator(0, 31, true);
1254   
1255  1 assertTrue(regions.hasNext());
1256  1 region = regions.next();
1257  1 assertEquals(5, region[0]);
1258  1 assertEquals(26, region[1]);
1259  1 region = regions.next();
1260  1 assertEquals(36, region[0]);
1261  1 assertEquals(44, region[1]);
1262  1 assertFalse(regions.hasNext());
1263   
1264    // multiple hidden regions
1265  1 h = new HiddenColumns();
1266  1 h.hideColumns(1, 1);
1267  1 h.hideColumns(3, 5);
1268  1 h.hideColumns(9, 11);
1269  1 h.hideColumns(22, 26);
1270   
1271  1 regions = h.getVisContigsIterator(0, 31, true);
1272   
1273  1 assertTrue(regions.hasNext());
1274  1 region = regions.next();
1275  1 assertEquals(0, region[0]);
1276  1 assertEquals(0, region[1]);
1277  1 region = regions.next();
1278  1 assertEquals(2, region[0]);
1279  1 assertEquals(2, region[1]);
1280  1 region = regions.next();
1281  1 assertEquals(6, region[0]);
1282  1 assertEquals(8, region[1]);
1283  1 region = regions.next();
1284  1 assertEquals(12, region[0]);
1285  1 assertEquals(21, region[1]);
1286  1 region = regions.next();
1287  1 assertEquals(27, region[0]);
1288  1 assertEquals(42, region[1]);
1289  1 assertFalse(regions.hasNext());
1290    }
1291   
1292    /*
1293    * the VisibleColsIterator is tested elsewhere, this just tests that
1294    * it can be retrieved from HiddenColumns
1295    */
 
1296  1 toggle @Test(groups = "Functional")
1297    public void testGetVisibleColsIterator()
1298    {
1299  1 HiddenColumns h = new HiddenColumns();
1300  1 Iterator<Integer> it = h.getVisibleColsIterator(0, 10);
1301   
1302  1 assertTrue(it instanceof RangeElementsIterator);
1303    }
1304   
 
1305  1 toggle @Test(groups = "Functional")
1306    public void testHashCode()
1307    {
1308  1 HiddenColumns h = new HiddenColumns();
1309  1 h.hideColumns(0, 25);
1310   
1311  1 int result = h.hashCode();
1312  1 assertTrue(result > 0);
1313   
1314  1 h.hideColumns(30, 50);
1315  1 assertTrue(h.hashCode() > 0);
1316  1 assertTrue(result != h.hashCode());
1317    }
1318    }