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.Iterator;
29 import java.util.List;
31 import org.testng.annotations.Test;
33 public class StartRegionIteratorTest
36 * Test the start region iterator
38 @Test(groups = { "Functional" })
39 public void testBasicBoundsIterator()
41 List<int[]> hiddenColumns = null;
43 // null hidden columns
44 Iterator<Integer> it = new StartRegionIterator(3, 10,
46 assertFalse(it.hasNext());
48 hiddenColumns = new ArrayList<>();
51 it = new StartRegionIterator(3, 10, hiddenColumns);
52 assertFalse(it.hasNext());
54 // add some hidden columns
55 hiddenColumns.add(new int[] { 5, 10 });
56 hiddenColumns.add(new int[] { 25, 40 });
58 it = new StartRegionIterator(3, 10, hiddenColumns);
59 assertTrue(it.hasNext());
60 Integer result = it.next();
61 assertEquals(5, (int) result);
62 assertFalse(it.hasNext());
64 it = new StartRegionIterator(3, 15, hiddenColumns);
65 assertTrue(it.hasNext());
67 assertEquals(5, (int) result);
68 assertFalse(it.hasNext());
70 it = new StartRegionIterator(3, 18, hiddenColumns);
71 assertTrue(it.hasNext());
73 assertEquals(5, (int) result);
74 assertFalse(it.hasNext());
76 it = new StartRegionIterator(3, 19, hiddenColumns);
77 assertTrue(it.hasNext());
79 assertEquals(5, (int) result);
80 assertTrue(it.hasNext());
82 assertEquals(19, (int) result);
83 assertFalse(it.hasNext());
85 hiddenColumns.add(new int[] { 47, 50 });
87 it = new StartRegionIterator(15, 60, hiddenColumns);
88 assertTrue(it.hasNext());
90 assertEquals(19, (int) result);
91 assertTrue(it.hasNext());
93 assertEquals(25, (int) result);
94 assertFalse(it.hasNext());
98 * Test the start region iterator with null cursor
100 @Test(groups = { "Functional" })
101 public void testBoundsIteratorUsingNullCursor()
103 List<int[]> hiddenColumns = null;
104 HiddenCursorPosition pos = null;
106 // null hidden columns
107 Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
109 assertFalse(it.hasNext());
111 hiddenColumns = new ArrayList<>();
114 it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
115 assertFalse(it.hasNext());
117 // add some hidden columns
118 hiddenColumns.add(new int[] { 5, 10 });
119 hiddenColumns.add(new int[] { 25, 40 });
121 it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
122 assertTrue(it.hasNext());
123 Integer result = it.next();
124 assertEquals(5, (int) result);
125 assertFalse(it.hasNext());
127 it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
128 assertTrue(it.hasNext());
130 assertEquals(5, (int) result);
131 assertFalse(it.hasNext());
133 it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
134 assertTrue(it.hasNext());
136 assertEquals(5, (int) result);
137 assertFalse(it.hasNext());
139 it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
140 assertTrue(it.hasNext());
142 assertEquals(5, (int) result);
143 assertTrue(it.hasNext());
145 assertEquals(19, (int) result);
146 assertFalse(it.hasNext());
148 hiddenColumns.add(new int[] { 47, 50 });
150 it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
151 assertTrue(it.hasNext());
153 assertEquals(19, (int) result);
154 assertTrue(it.hasNext());
156 assertEquals(25, (int) result);
157 assertFalse(it.hasNext());
161 * Test the start region iterator with nonnull cursor
163 @Test(groups = { "Functional" })
164 public void testBoundsIteratorUsingCursor()
166 List<int[]> hiddenColumns = new ArrayList<>();
168 // add some hidden columns
169 hiddenColumns.add(new int[] { 5, 10 });
170 hiddenColumns.add(new int[] { 25, 40 });
172 HiddenCursorPosition pos = new HiddenCursorPosition(0, 0);
174 Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
176 assertTrue(it.hasNext());
177 Integer result = it.next();
178 assertEquals(5, (int) result);
179 assertFalse(it.hasNext());
181 it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
182 assertTrue(it.hasNext());
184 assertEquals(5, (int) result);
185 assertFalse(it.hasNext());
187 it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
188 assertTrue(it.hasNext());
190 assertEquals(5, (int) result);
191 assertFalse(it.hasNext());
193 it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
194 assertTrue(it.hasNext());
196 assertEquals(5, (int) result);
197 assertTrue(it.hasNext());
199 assertEquals(19, (int) result);
200 assertFalse(it.hasNext());
202 pos = new HiddenCursorPosition(1, 6);
203 hiddenColumns.add(new int[] { 47, 50 });
205 it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
206 assertTrue(it.hasNext());
208 assertEquals(19, (int) result);
209 assertTrue(it.hasNext());
211 assertEquals(25, (int) result);
212 assertFalse(it.hasNext());