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, hiddenColumns);
45 assertFalse(it.hasNext());
47 hiddenColumns = new ArrayList<>();
50 it = new StartRegionIterator(3, 10, hiddenColumns);
51 assertFalse(it.hasNext());
53 // add some hidden columns
54 hiddenColumns.add(new int[] { 5, 10 });
55 hiddenColumns.add(new int[] { 25, 40 });
57 it = new StartRegionIterator(3, 10, hiddenColumns);
58 assertTrue(it.hasNext());
59 Integer result = it.next();
60 assertEquals(5, (int) result);
61 assertFalse(it.hasNext());
63 it = new StartRegionIterator(3, 15, hiddenColumns);
64 assertTrue(it.hasNext());
66 assertEquals(5, (int) result);
67 assertFalse(it.hasNext());
69 it = new StartRegionIterator(3, 18, hiddenColumns);
70 assertTrue(it.hasNext());
72 assertEquals(5, (int) result);
73 assertFalse(it.hasNext());
75 it = new StartRegionIterator(3, 19, hiddenColumns);
76 assertTrue(it.hasNext());
78 assertEquals(5, (int) result);
79 assertTrue(it.hasNext());
81 assertEquals(19, (int) result);
82 assertFalse(it.hasNext());
84 hiddenColumns.add(new int[] { 47, 50 });
86 it = new StartRegionIterator(15, 60, hiddenColumns);
87 assertTrue(it.hasNext());
89 assertEquals(19, (int) result);
90 assertTrue(it.hasNext());
92 assertEquals(25, (int) result);
93 assertFalse(it.hasNext());
97 * Test the start region iterator with null cursor
99 @Test(groups = { "Functional" })
100 public void testBoundsIteratorUsingNullCursor()
102 List<int[]> hiddenColumns = null;
103 HiddenCursorPosition pos = null;
105 // null hidden columns
106 Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
108 assertFalse(it.hasNext());
110 hiddenColumns = new ArrayList<>();
113 it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
114 assertFalse(it.hasNext());
116 // add some hidden columns
117 hiddenColumns.add(new int[] { 5, 10 });
118 hiddenColumns.add(new int[] { 25, 40 });
120 it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
121 assertTrue(it.hasNext());
122 Integer result = it.next();
123 assertEquals(5, (int) result);
124 assertFalse(it.hasNext());
126 it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
127 assertTrue(it.hasNext());
129 assertEquals(5, (int) result);
130 assertFalse(it.hasNext());
132 it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
133 assertTrue(it.hasNext());
135 assertEquals(5, (int) result);
136 assertFalse(it.hasNext());
138 it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
139 assertTrue(it.hasNext());
141 assertEquals(5, (int) result);
142 assertTrue(it.hasNext());
144 assertEquals(19, (int) result);
145 assertFalse(it.hasNext());
147 hiddenColumns.add(new int[] { 47, 50 });
149 it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
150 assertTrue(it.hasNext());
152 assertEquals(19, (int) result);
153 assertTrue(it.hasNext());
155 assertEquals(25, (int) result);
156 assertFalse(it.hasNext());
160 * Test the start region iterator with nonnull cursor
162 @Test(groups = { "Functional" })
163 public void testBoundsIteratorUsingCursor()
165 List<int[]> hiddenColumns = new ArrayList<>();
167 // add some hidden columns
168 hiddenColumns.add(new int[] { 5, 10 });
169 hiddenColumns.add(new int[] { 25, 40 });
171 HiddenCursorPosition pos = new HiddenCursorPosition(0, 0);
173 Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
175 assertTrue(it.hasNext());
176 Integer result = it.next();
177 assertEquals(5, (int) result);
178 assertFalse(it.hasNext());
180 it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
181 assertTrue(it.hasNext());
183 assertEquals(5, (int) result);
184 assertFalse(it.hasNext());
186 it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
187 assertTrue(it.hasNext());
189 assertEquals(5, (int) result);
190 assertFalse(it.hasNext());
192 it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
193 assertTrue(it.hasNext());
195 assertEquals(5, (int) result);
196 assertTrue(it.hasNext());
198 assertEquals(19, (int) result);
199 assertFalse(it.hasNext());
201 pos = new HiddenCursorPosition(1, 6);
202 hiddenColumns.add(new int[] { 47, 50 });
204 it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
205 assertTrue(it.hasNext());
207 assertEquals(19, (int) result);
208 assertTrue(it.hasNext());
210 assertEquals(25, (int) result);
211 assertFalse(it.hasNext());