JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / datamodel / RangeElementsIteratorTest.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.assertTrue;
24
25 import java.util.Iterator;
26 import java.util.NoSuchElementException;
27
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
30
31 public class RangeElementsIteratorTest
32 {
33   HiddenColumns hiddenCols;
34
35   HiddenColumns hiddenColsAtStart;
36
37   @BeforeClass(groups = { "Functional" })
38   public void setup()
39   {
40     hiddenCols = new HiddenColumns();
41     hiddenCols.hideColumns(2, 4);
42
43     hiddenColsAtStart = new HiddenColumns();
44     hiddenColsAtStart.hideColumns(0, 2);
45   }
46
47   /*
48    * Test iterator iterates correctly through the columns
49    * when alignment has hidden cols
50    */
51   @Test(groups = { "Functional" })
52   public void testHasNextAndNextWithHidden()
53   {
54     Iterator<Integer> it = hiddenCols.getVisibleColsIterator(0, 6);
55     int count = 0;
56     while (it.hasNext())
57     {
58       int result = it.next();
59       System.out.println(result);
60       count++;
61     }
62     assertTrue(count == 4, "hasNext() is false after 4 iterations");
63   }
64
65   /*
66    * Test iterator iterates correctly through the columns
67    * when alignment has no hidden cols
68    */
69   @Test(groups = { "Functional" })
70   public void testHasNextAndNextNoHidden()
71   {
72     HiddenColumns test = new HiddenColumns();
73     Iterator<Integer> it2 = test.getVisibleColsIterator(0, 3);
74     int count = 0;
75     while (it2.hasNext())
76     {
77       it2.next();
78       count++;
79     }
80     assertTrue(count == 4, "hasNext() is false after 4 iterations");
81   }
82
83   /*
84    * Test iterator iterates correctly through the columns
85    * when alignment has hidden cols at start
86    */
87   @Test(groups = { "Functional" })
88   public void testHasNextAndNextStartHidden()
89   {
90     Iterator<Integer> it3 = hiddenColsAtStart.getVisibleColsIterator(0, 6);
91     int count = 0;
92     while (it3.hasNext())
93     {
94       it3.next();
95       count++;
96     }
97     assertTrue(count == 4, "hasNext() is false after 4 iterations");
98   }
99
100   /*
101    * Test iterator iterates correctly through the columns
102    * when alignment has hidden cols at end
103    */
104   @Test(groups = { "Functional" })
105   public void testHasNextAndNextEndHidden()
106   {
107     Iterator<Integer> it4 = hiddenCols.getVisibleColsIterator(0, 4);
108     int count = 0;
109     while (it4.hasNext())
110     {
111       it4.next();
112       count++;
113     }
114     assertTrue(count == 2, "hasNext() is false after 2 iterations");
115
116   }
117
118   /*
119    * Test iterator always throws NoSuchElementException at end of iteration
120    * when alignment has hidden cols
121    */
122   @Test(
123     groups =
124     { "Functional" },
125     expectedExceptions =
126     { NoSuchElementException.class })
127   public void testLastNextWithHidden() throws NoSuchElementException
128   {
129     Iterator<Integer> it = hiddenCols.getVisibleColsIterator(0, 3);
130     while (it.hasNext())
131     {
132       it.next();
133     }
134     it.next();
135   }
136
137   /*
138    * Test iterator always throws NoSuchElementException at end of iteration
139    * when alignment has no hidden cols
140    */
141   @Test(
142     groups =
143     { "Functional" },
144     expectedExceptions =
145     { NoSuchElementException.class })
146   public void testLastNextNoHidden() throws NoSuchElementException
147   {
148     HiddenColumns test = new HiddenColumns();
149     Iterator<Integer> it2 = test.getVisibleColsIterator(0, 3);
150     while (it2.hasNext())
151     {
152       it2.next();
153     }
154     it2.next();
155   }
156
157   /*
158    * Test iterator always throws NoSuchElementException at end of iteration
159    * when alignment has hidden cols at start
160    */
161   @Test(
162     groups =
163     { "Functional" },
164     expectedExceptions =
165     { NoSuchElementException.class })
166   public void testLastNextStartHidden() throws NoSuchElementException
167   {
168     Iterator<Integer> it3 = hiddenColsAtStart.getVisibleColsIterator(0, 6);
169     while (it3.hasNext())
170     {
171       it3.next();
172     }
173     it3.next();
174   }
175
176   /*
177    * Test iterator always throws NoSuchElementException at end of iteration
178    * when alignment has hidden cols at end
179    */
180   @Test(
181     groups =
182     { "Functional" },
183     expectedExceptions =
184     { NoSuchElementException.class })
185   public void testLastNextEndHidden() throws NoSuchElementException
186   {
187     Iterator<Integer> it4 = hiddenCols.getVisibleColsIterator(0, 4);
188     while (it4.hasNext())
189     {
190       it4.next();
191     }
192     it4.next();
193   }
194
195   /*
196    * Test calls to remove throw UnsupportedOperationException
197    */
198   @Test(
199     groups =
200     { "Functional" },
201     expectedExceptions =
202     { UnsupportedOperationException.class })
203   public void testRemove() throws UnsupportedOperationException
204   {
205     Iterator<Integer> it = hiddenCols.getVisibleColsIterator(0, 3);
206     it.remove();
207   }
208 }