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