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.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
27 import java.util.ArrayList;
28 import java.util.List;
30 import org.testng.annotations.Test;
32 public class VisibleContigsIteratorTest
35 * Test the iterator with single visible regions
37 @Test(groups = { "Functional" })
38 public void testSimpleVisibleRegions()
40 List<int[]> hiddenColumns = null;
42 // null hidden columns
43 VisibleContigsIterator it = new VisibleContigsIterator(3, 10,
45 assertTrue(it.hasNext());
46 assertFalse(it.endsAtHidden());
47 int[] result = it.next();
48 assertEquals(3, result[0]);
49 assertEquals(9, result[1]);
50 assertFalse(it.hasNext());
51 assertFalse(it.endsAtHidden());
53 hiddenColumns = new ArrayList<>();
56 it = new VisibleContigsIterator(3, 10,
58 assertTrue(it.hasNext());
59 assertFalse(it.endsAtHidden());
61 assertEquals(3, result[0]);
62 assertEquals(9, result[1]);
63 assertFalse(it.hasNext());
64 assertFalse(it.endsAtHidden());
66 // hidden columns, but not where we are looking
67 hiddenColumns.add(new int[] { 5, 10 });
68 hiddenColumns.add(new int[] { 25, 40 });
70 it = new VisibleContigsIterator(2, 3, hiddenColumns);
71 assertTrue(it.hasNext());
72 assertFalse(it.endsAtHidden());
74 assertEquals(2, result[0]);
75 assertEquals(2, result[1]);
76 assertFalse(it.hasNext());
77 assertFalse(it.endsAtHidden());
79 it = new VisibleContigsIterator(5, 7, hiddenColumns);
80 assertFalse(it.hasNext());
81 assertFalse(it.endsAtHidden());
83 it = new VisibleContigsIterator(11, 15, hiddenColumns);
84 assertTrue(it.hasNext());
85 assertFalse(it.endsAtHidden());
87 assertEquals(11, result[0]);
88 assertEquals(14, result[1]);
89 assertFalse(it.hasNext());
90 assertFalse(it.endsAtHidden());
92 it = new VisibleContigsIterator(50, 60, hiddenColumns);
93 assertTrue(it.hasNext());
94 assertFalse(it.endsAtHidden());
96 assertEquals(50, result[0]);
97 assertEquals(59, result[1]);
98 assertFalse(it.hasNext());
99 assertFalse(it.endsAtHidden());
103 * Test the iterator with multiple visible regions
105 @Test(groups = { "Functional" })
106 public void testMultipleVisibleRegions()
108 List<int[]> hiddenColumns = new ArrayList<>();
109 hiddenColumns.add(new int[] { 5, 10 });
110 hiddenColumns.add(new int[] { 25, 40 });
112 // all hidden columns covered
113 VisibleContigsIterator it = new VisibleContigsIterator(3, 50,
115 assertTrue(it.hasNext());
116 assertFalse(it.endsAtHidden());
117 int[] result = it.next();
118 assertEquals(3, result[0]);
119 assertEquals(4, result[1]);
121 assertTrue(it.hasNext());
122 assertFalse(it.endsAtHidden());
124 assertEquals(11, result[0]);
125 assertEquals(24, result[1]);
127 assertTrue(it.hasNext());
128 assertFalse(it.endsAtHidden());
130 assertEquals(41, result[0]);
131 assertEquals(49, result[1]);
133 assertFalse(it.hasNext());
134 assertFalse(it.endsAtHidden());
138 * Test the iterator with regions which start/end at hidden region edges
140 @Test(groups = { "Functional" })
141 public void testVisibleRegionsAtHiddenEdges()
143 List<int[]> hiddenColumns = new ArrayList<>();
144 hiddenColumns.add(new int[] { 5, 10 });
145 hiddenColumns.add(new int[] { 25, 40 });
147 VisibleContigsIterator it = new VisibleContigsIterator(0, 10,
149 assertTrue(it.hasNext());
150 assertTrue(it.endsAtHidden());
151 int[] result = it.next();
152 assertEquals(0, result[0]);
153 assertEquals(4, result[1]);
154 assertFalse(it.hasNext());
155 assertTrue(it.endsAtHidden());
157 it = new VisibleContigsIterator(2, 11, hiddenColumns);
158 assertTrue(it.hasNext());
159 assertTrue(it.endsAtHidden());
161 assertEquals(2, result[0]);
162 assertEquals(4, result[1]);
163 assertFalse(it.hasNext());
164 assertTrue(it.endsAtHidden());
166 it = new VisibleContigsIterator(2, 12, hiddenColumns);
167 assertTrue(it.hasNext());
168 assertFalse(it.endsAtHidden());
170 assertEquals(2, result[0]);
171 assertEquals(4, result[1]);
172 assertTrue(it.hasNext());
173 assertFalse(it.endsAtHidden());
175 assertEquals(11, result[0]);
176 assertEquals(11, result[1]);
177 assertFalse(it.hasNext());
178 assertFalse(it.endsAtHidden());
180 it = new VisibleContigsIterator(13, 25, hiddenColumns);
181 assertTrue(it.hasNext());
182 assertFalse(it.endsAtHidden());
184 assertEquals(13, result[0]);
185 assertEquals(24, result[1]);
186 assertFalse(it.hasNext());
188 it = new VisibleContigsIterator(13, 26, hiddenColumns);
189 assertTrue(it.hasNext());
190 assertTrue(it.endsAtHidden());
192 assertEquals(13, result[0]);
193 assertEquals(24, result[1]);
194 assertFalse(it.hasNext());
196 it = new VisibleContigsIterator(13, 27, hiddenColumns);
197 assertTrue(it.hasNext());
198 assertTrue(it.endsAtHidden());
200 assertEquals(13, result[0]);
201 assertEquals(24, result[1]);
202 assertFalse(it.hasNext());
204 it = new VisibleContigsIterator(13, 41, hiddenColumns);
205 assertTrue(it.hasNext());
206 assertTrue(it.endsAtHidden());
208 assertEquals(13, result[0]);
209 assertEquals(24, result[1]);
210 assertFalse(it.hasNext());
212 it = new VisibleContigsIterator(13, 42, hiddenColumns);
213 assertTrue(it.hasNext());
214 assertFalse(it.endsAtHidden());
216 assertEquals(13, result[0]);
217 assertEquals(24, result[1]);
218 assertTrue(it.hasNext());
220 assertEquals(41, result[0]);
221 assertEquals(41, result[1]);