JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / datamodel / StartRegionIteratorTest.java
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.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
26
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
30
31 import org.testng.annotations.Test;
32
33 public class StartRegionIteratorTest
34 {
35   /**
36    * Test the start region iterator
37    */
38   @Test(groups = { "Functional" })
39   public void testBasicBoundsIterator()
40   {
41     List<int[]> hiddenColumns = null;
42
43     // null hidden columns
44     Iterator<Integer> it = new StartRegionIterator(3, 10, hiddenColumns);
45     assertFalse(it.hasNext());
46
47     hiddenColumns = new ArrayList<>();
48
49     // no hidden columns
50     it = new StartRegionIterator(3, 10, hiddenColumns);
51     assertFalse(it.hasNext());
52
53     // add some hidden columns
54     hiddenColumns.add(new int[] { 5, 10 });
55     hiddenColumns.add(new int[] { 25, 40 });
56
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());
62
63     it = new StartRegionIterator(3, 15, hiddenColumns);
64     assertTrue(it.hasNext());
65     result = it.next();
66     assertEquals(5, (int) result);
67     assertFalse(it.hasNext());
68
69     it = new StartRegionIterator(3, 18, hiddenColumns);
70     assertTrue(it.hasNext());
71     result = it.next();
72     assertEquals(5, (int) result);
73     assertFalse(it.hasNext());
74
75     it = new StartRegionIterator(3, 19, hiddenColumns);
76     assertTrue(it.hasNext());
77     result = it.next();
78     assertEquals(5, (int) result);
79     assertTrue(it.hasNext());
80     result = it.next();
81     assertEquals(19, (int) result);
82     assertFalse(it.hasNext());
83
84     hiddenColumns.add(new int[] { 47, 50 });
85
86     it = new StartRegionIterator(15, 60, hiddenColumns);
87     assertTrue(it.hasNext());
88     result = it.next();
89     assertEquals(19, (int) result);
90     assertTrue(it.hasNext());
91     result = it.next();
92     assertEquals(25, (int) result);
93     assertFalse(it.hasNext());
94   }
95
96   /**
97    * Test the start region iterator with null cursor
98    */
99   @Test(groups = { "Functional" })
100   public void testBoundsIteratorUsingNullCursor()
101   {
102     List<int[]> hiddenColumns = null;
103     HiddenCursorPosition pos = null;
104
105     // null hidden columns
106     Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
107             hiddenColumns);
108     assertFalse(it.hasNext());
109
110     hiddenColumns = new ArrayList<>();
111
112     // no hidden columns
113     it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
114     assertFalse(it.hasNext());
115
116     // add some hidden columns
117     hiddenColumns.add(new int[] { 5, 10 });
118     hiddenColumns.add(new int[] { 25, 40 });
119
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());
125
126     it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
127     assertTrue(it.hasNext());
128     result = it.next();
129     assertEquals(5, (int) result);
130     assertFalse(it.hasNext());
131
132     it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
133     assertTrue(it.hasNext());
134     result = it.next();
135     assertEquals(5, (int) result);
136     assertFalse(it.hasNext());
137
138     it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
139     assertTrue(it.hasNext());
140     result = it.next();
141     assertEquals(5, (int) result);
142     assertTrue(it.hasNext());
143     result = it.next();
144     assertEquals(19, (int) result);
145     assertFalse(it.hasNext());
146
147     hiddenColumns.add(new int[] { 47, 50 });
148
149     it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
150     assertTrue(it.hasNext());
151     result = it.next();
152     assertEquals(19, (int) result);
153     assertTrue(it.hasNext());
154     result = it.next();
155     assertEquals(25, (int) result);
156     assertFalse(it.hasNext());
157   }
158
159   /**
160    * Test the start region iterator with nonnull cursor
161    */
162   @Test(groups = { "Functional" })
163   public void testBoundsIteratorUsingCursor()
164   {
165     List<int[]> hiddenColumns = new ArrayList<>();
166
167     // add some hidden columns
168     hiddenColumns.add(new int[] { 5, 10 });
169     hiddenColumns.add(new int[] { 25, 40 });
170
171     HiddenCursorPosition pos = new HiddenCursorPosition(0, 0);
172
173     Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
174             hiddenColumns);
175     assertTrue(it.hasNext());
176     Integer result = it.next();
177     assertEquals(5, (int) result);
178     assertFalse(it.hasNext());
179
180     it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
181     assertTrue(it.hasNext());
182     result = it.next();
183     assertEquals(5, (int) result);
184     assertFalse(it.hasNext());
185
186     it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
187     assertTrue(it.hasNext());
188     result = it.next();
189     assertEquals(5, (int) result);
190     assertFalse(it.hasNext());
191
192     it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
193     assertTrue(it.hasNext());
194     result = it.next();
195     assertEquals(5, (int) result);
196     assertTrue(it.hasNext());
197     result = it.next();
198     assertEquals(19, (int) result);
199     assertFalse(it.hasNext());
200
201     pos = new HiddenCursorPosition(1, 6);
202     hiddenColumns.add(new int[] { 47, 50 });
203
204     it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
205     assertTrue(it.hasNext());
206     result = it.next();
207     assertEquals(19, (int) result);
208     assertTrue(it.hasNext());
209     result = it.next();
210     assertEquals(25, (int) result);
211     assertFalse(it.hasNext());
212   }
213 }