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.assertTrue;
25 import jalview.analysis.AlignmentGenerator;
27 import java.util.Hashtable;
28 import java.util.NoSuchElementException;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.Test;
33 public class VisibleRowsIteratorTest
41 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
43 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences2 = new Hashtable<SequenceI, SequenceCollectionI>();
45 @BeforeClass(groups = { "Functional" })
48 // create random alignment
49 AlignmentGenerator gen = new AlignmentGenerator(false);
50 al = gen.generate(20, 15, 123, 5, 5);
51 if (!hiddenRepSequences.isEmpty())
53 al.getHiddenSequences().showAll(hiddenRepSequences);
55 hideSequences(al, hiddenRepSequences, 2, 4);
57 al2 = gen.generate(20, 15, 123, 5, 5);
58 if (!hiddenRepSequences2.isEmpty())
60 al2.getHiddenSequences().showAll(hiddenRepSequences2);
62 hideSequences(al2, hiddenRepSequences2, 0, 2);
64 al3 = gen.generate(20, 15, 123, 5, 5);
68 * Test iterator iterates correctly through the rows
69 * when alignment has hidden rows
71 @Test(groups = { "Functional" })
72 public void testHasNextAndNextWithHidden()
74 VisibleRowsIterator it = new VisibleRowsIterator(0, 6, al);
81 assertTrue(count == 4, "hasNext() is false after 4 iterations");
85 * Test iterator iterates correctly through the rows
86 * when alignment has no hidden rows
88 @Test(groups = { "Functional" })
89 public void testHasNextAndNextNoHidden()
91 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al3);
98 assertTrue(count == 4, "hasNext() is false after 4 iterations");
102 * Test iterator iterates correctly through the rows
103 * when alignment has hidden rows at start
105 @Test(groups = { "Functional" })
106 public void testHasNextAndNextStartHidden()
108 VisibleRowsIterator it = new VisibleRowsIterator(0, 6, al2);
115 assertTrue(count == 4, "hasNext() is false after 4 iterations");
119 * Test iterator iterates correctly through the rows
120 * when alignment has hidden rows at end
122 @Test(groups = { "Functional" })
123 public void testHasNextAndNextEndHidden()
125 VisibleRowsIterator it = new VisibleRowsIterator(0, 4, al);
132 assertTrue(count == 2, "hasNext() is false after 2 iterations");
136 * Test iterator always throws NoSuchElementException at end of iteration
137 * when alignment has hidden rows
143 { NoSuchElementException.class })
144 public void testLastNextWithHidden() throws NoSuchElementException
146 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al);
155 * Test iterator always throws NoSuchElementException at end of iteration
156 * when alignment has no hidden rows
162 { NoSuchElementException.class })
163 public void testLastNextNoHidden() throws NoSuchElementException
165 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al3);
174 * Test iterator always throws NoSuchElementException at end of iteration
175 * when alignment has hidden rows at start
181 { NoSuchElementException.class })
182 public void testLastNextStartHidden() throws NoSuchElementException
184 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al2);
193 * Test iterator always throws NoSuchElementException at end of iteration
194 * when alignment has hidden rows at end
200 { NoSuchElementException.class })
201 public void testLastNextEndHidden() throws NoSuchElementException
203 VisibleRowsIterator it = new VisibleRowsIterator(0, 4, al);
212 * Test calls to remove throw UnsupportedOperationException
218 { UnsupportedOperationException.class })
219 public void testRemove() throws UnsupportedOperationException
221 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al);
226 * Hide sequences between start and end
228 private void hideSequences(AlignmentI alignment,
229 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences,
232 SequenceI[] allseqs = alignment.getSequencesArray();
233 SequenceGroup theseSeqs = new SequenceGroup();
235 for (int i = start; i <= end; i++)
237 theseSeqs.addSequence(allseqs[i], false);
238 alignment.getHiddenSequences().hideSequence(allseqs[i]);
241 hiddenRepSequences.put(allseqs[start], theseSeqs);