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
140 groups = { "Functional" },
141 expectedExceptions = { NoSuchElementException.class })
142 public void testLastNextWithHidden() throws NoSuchElementException
144 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al);
153 * Test iterator always throws NoSuchElementException at end of iteration
154 * when alignment has no hidden rows
157 groups = { "Functional" },
158 expectedExceptions = { NoSuchElementException.class })
159 public void testLastNextNoHidden() throws NoSuchElementException
161 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al3);
170 * Test iterator always throws NoSuchElementException at end of iteration
171 * when alignment has hidden rows at start
174 groups = { "Functional" },
175 expectedExceptions = { NoSuchElementException.class })
176 public void testLastNextStartHidden() throws NoSuchElementException
178 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al2);
187 * Test iterator always throws NoSuchElementException at end of iteration
188 * when alignment has hidden rows at end
191 groups = { "Functional" },
192 expectedExceptions = { NoSuchElementException.class })
193 public void testLastNextEndHidden() throws NoSuchElementException
195 VisibleRowsIterator it = new VisibleRowsIterator(0, 4, al);
204 * Test calls to remove throw UnsupportedOperationException
207 groups = { "Functional" },
208 expectedExceptions = { UnsupportedOperationException.class })
209 public void testRemove() throws UnsupportedOperationException
211 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al);
216 * Hide sequences between start and end
218 private void hideSequences(AlignmentI alignment,
219 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences,
222 SequenceI[] allseqs = alignment.getSequencesArray();
223 SequenceGroup theseSeqs = new SequenceGroup();
225 for (int i = start; i <= end; i++)
227 theseSeqs.addSequence(allseqs[i], false);
228 alignment.getHiddenSequences().hideSequence(allseqs[i]);
231 hiddenRepSequences.put(allseqs[start], theseSeqs);