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 AllRowsIteratorTest
37 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
42 // create random alignment
43 AlignmentGenerator gen = new AlignmentGenerator(false);
44 al = gen.generate(20, 15, 123, 5, 5);
45 if (!hiddenRepSequences.isEmpty())
47 al.getHiddenSequences().showAll(hiddenRepSequences);
53 * Test iterator iterates through collection correctly
55 @Test(groups = { "Functional" })
56 public void testHasNextAndNext()
58 AllRowsIterator it = new AllRowsIterator(0, 3, al);
65 assertTrue(count == 4, "hasNext() is false after 4 iterations");
69 * Test iterator throws NoSuchElementException at end of iteration
72 groups = { "Functional" },
73 expectedExceptions = { NoSuchElementException.class })
74 public void testLastNext() throws NoSuchElementException
76 AllRowsIterator it = new AllRowsIterator(0, 3, al);
85 * Test iterator throws UnsupportedOperationException on call to remove
88 groups = { "Functional" },
89 expectedExceptions = { UnsupportedOperationException.class })
90 public void testRemove() throws UnsupportedOperationException
92 AllRowsIterator it = new AllRowsIterator(0, 3, al);
98 * Hide sequences between start and end
100 private void hideSequences(int start, int end)
102 SequenceI[] allseqs = al.getSequencesArray();
103 SequenceGroup theseSeqs = new SequenceGroup();
105 for (int i = start; i <= end; i++)
107 theseSeqs.addSequence(allseqs[i], false);
108 al.getHiddenSequences().hideSequence(allseqs[i]);
111 hiddenRepSequences.put(allseqs[start], theseSeqs);
115 * Test iterator behaves correctly when there is only one element in the collection
117 @Test(groups = { "Functional" })
118 public void testOneElement()
120 AllRowsIterator it = new AllRowsIterator(0, 0, al);
127 assertTrue(count == 1, "hasNext() is false after 1 iteration");