JAL=2674 Removed getHiddenColumnsCopy
[jalview.git] / test / jalview / datamodel / VisibleColsIteratorTest.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 VisibleColsIteratorTest
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       it.next();
59       count++;
60     }
61     assertTrue(count == 4, "hasNext() is false after 4 iterations");
62   }
63
64   /*
65    * Test iterator iterates correctly through the columns
66    * when alignment has no hidden cols
67    */
68   @Test(groups = { "Functional" })
69   public void testHasNextAndNextNoHidden()
70   {
71     HiddenColumns test = new HiddenColumns();
72     Iterator<Integer> it2 = test.getVisibleColsIterator(0, 3);
73     int count = 0;
74     while (it2.hasNext())
75     {
76       it2.next();
77       count++;
78     }
79     assertTrue(count == 4, "hasNext() is false after 4 iterations");
80   }
81
82   /*
83    * Test iterator iterates correctly through the columns
84    * when alignment has hidden cols at start
85    */
86   @Test(groups = { "Functional" })
87   public void testHasNextAndNextStartHidden()
88   {
89     Iterator<Integer> it3 = hiddenColsAtStart.getVisibleColsIterator(0, 6);
90     int count = 0;
91     while (it3.hasNext())
92     {
93       it3.next();
94       count++;
95     }
96     assertTrue(count == 4, "hasNext() is false after 4 iterations");
97   }
98
99   /*
100    * Test iterator iterates correctly through the columns
101    * when alignment has hidden cols at end
102    */
103   @Test(groups = { "Functional" })
104   public void testHasNextAndNextEndHidden()
105   {
106     Iterator<Integer> it4 = hiddenCols.getVisibleColsIterator(0, 4);
107     int count = 0;
108     while (it4.hasNext())
109     {
110       it4.next();
111       count++;
112     }
113     assertTrue(count == 2, "hasNext() is false after 2 iterations");
114
115   }
116
117   /*
118    * Test iterator always throws NoSuchElementException at end of iteration
119    * when alignment has hidden cols
120    */
121   @Test(
122     groups = { "Functional" },
123     expectedExceptions = { NoSuchElementException.class })
124   public void testLastNextWithHidden() throws NoSuchElementException
125   {
126     Iterator<Integer> it = hiddenCols.getVisibleColsIterator(0, 3);
127     while (it.hasNext())
128     {
129       it.next();
130     }
131     it.next();
132   }
133
134   /*
135    * Test iterator always throws NoSuchElementException at end of iteration
136    * when alignment has no hidden cols
137    */
138   @Test(
139     groups = { "Functional" },
140     expectedExceptions = { NoSuchElementException.class })
141   public void testLastNextNoHidden() throws NoSuchElementException
142   {
143     HiddenColumns test = new HiddenColumns();
144     Iterator<Integer> it2 = test.getVisibleColsIterator(0, 3);
145     while (it2.hasNext())
146     {
147       it2.next();
148     }
149     it2.next();
150   }
151
152   /*
153    * Test iterator always throws NoSuchElementException at end of iteration
154    * when alignment has hidden cols at start
155    */
156   @Test(
157     groups = { "Functional" },
158     expectedExceptions = { NoSuchElementException.class })
159   public void testLastNextStartHidden() throws NoSuchElementException
160   {
161     Iterator<Integer> it3 = hiddenColsAtStart.getVisibleColsIterator(0, 6);
162     while (it3.hasNext())
163     {
164       it3.next();
165     }
166     it3.next();
167   }
168
169   /*
170    * Test iterator always throws NoSuchElementException at end of iteration
171    * when alignment has hidden cols at end
172    */
173   @Test(
174     groups = { "Functional" },
175     expectedExceptions = { NoSuchElementException.class })
176   public void testLastNextEndHidden() throws NoSuchElementException
177   {
178     Iterator<Integer> it4 = hiddenCols.getVisibleColsIterator(0, 4);
179     while (it4.hasNext())
180     {
181       it4.next();
182     }
183     it4.next();
184   }
185
186   /*
187    * Test calls to remove throw UnsupportedOperationException
188    */
189   @Test(
190     groups = { "Functional" },
191     expectedExceptions = { UnsupportedOperationException.class })
192   public void testRemove() throws UnsupportedOperationException
193   {
194     Iterator<Integer> it = hiddenCols.getVisibleColsIterator(0, 3);
195     it.remove();
196   }
197 }