Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.datamodel

File VisibleRowsIteratorTest.java

 

Code metrics

22
58
11
1
233
150
22
0.38
5.27
11
2

Classes

Class Line # Actions
VisibleRowsIteratorTest 33 58 22 4
0.9560439695.6%
 

Contributing tests

This file is covered by 9 tests. .

Source view

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 jalview.analysis.AlignmentGenerator;
26   
27    import java.util.Hashtable;
28    import java.util.NoSuchElementException;
29   
30    import org.testng.annotations.BeforeClass;
31    import org.testng.annotations.Test;
32   
 
33    public class VisibleRowsIteratorTest
34    {
35    AlignmentI al;
36   
37    AlignmentI al2;
38   
39    AlignmentI al3;
40   
41    Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
42   
43    Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences2 = new Hashtable<SequenceI, SequenceCollectionI>();
44   
 
45  1 toggle @BeforeClass(groups = { "Functional" })
46    public void setup()
47    {
48    // create random alignment
49  1 AlignmentGenerator gen = new AlignmentGenerator(false);
50  1 al = gen.generate(20, 15, 123, 5, 5);
51  1 if (!hiddenRepSequences.isEmpty())
52    {
53  0 al.getHiddenSequences().showAll(hiddenRepSequences);
54    }
55  1 hideSequences(al, hiddenRepSequences, 2, 4);
56   
57  1 al2 = gen.generate(20, 15, 123, 5, 5);
58  1 if (!hiddenRepSequences2.isEmpty())
59    {
60  0 al2.getHiddenSequences().showAll(hiddenRepSequences2);
61    }
62  1 hideSequences(al2, hiddenRepSequences2, 0, 2);
63   
64  1 al3 = gen.generate(20, 15, 123, 5, 5);
65    }
66   
67    /*
68    * Test iterator iterates correctly through the rows
69    * when alignment has hidden rows
70    */
 
71  1 toggle @Test(groups = { "Functional" })
72    public void testHasNextAndNextWithHidden()
73    {
74  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 6, al);
75  1 int count = 0;
76  5 while (it.hasNext())
77    {
78  4 it.next();
79  4 count++;
80    }
81  1 assertTrue(count == 4, "hasNext() is false after 4 iterations");
82    }
83   
84    /*
85    * Test iterator iterates correctly through the rows
86    * when alignment has no hidden rows
87    */
 
88  1 toggle @Test(groups = { "Functional" })
89    public void testHasNextAndNextNoHidden()
90    {
91  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al3);
92  1 int count = 0;
93  5 while (it.hasNext())
94    {
95  4 it.next();
96  4 count++;
97    }
98  1 assertTrue(count == 4, "hasNext() is false after 4 iterations");
99    }
100   
101    /*
102    * Test iterator iterates correctly through the rows
103    * when alignment has hidden rows at start
104    */
 
105  1 toggle @Test(groups = { "Functional" })
106    public void testHasNextAndNextStartHidden()
107    {
108  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 6, al2);
109  1 int count = 0;
110  5 while (it.hasNext())
111    {
112  4 it.next();
113  4 count++;
114    }
115  1 assertTrue(count == 4, "hasNext() is false after 4 iterations");
116    }
117   
118    /*
119    * Test iterator iterates correctly through the rows
120    * when alignment has hidden rows at end
121    */
 
122  1 toggle @Test(groups = { "Functional" })
123    public void testHasNextAndNextEndHidden()
124    {
125  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 4, al);
126  1 int count = 0;
127  3 while (it.hasNext())
128    {
129  2 it.next();
130  2 count++;
131    }
132  1 assertTrue(count == 2, "hasNext() is false after 2 iterations");
133    }
134   
135    /*
136    * Test iterator always throws NoSuchElementException at end of iteration
137    * when alignment has hidden rows
138    */
 
139  1 toggle @Test(
140    groups = { "Functional" },
141    expectedExceptions = { NoSuchElementException.class })
142    public void testLastNextWithHidden() throws NoSuchElementException
143    {
144  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al);
145  3 while (it.hasNext())
146    {
147  2 it.next();
148    }
149  1 it.next();
150    }
151   
152    /*
153    * Test iterator always throws NoSuchElementException at end of iteration
154    * when alignment has no hidden rows
155    */
 
156  1 toggle @Test(
157    groups = { "Functional" },
158    expectedExceptions = { NoSuchElementException.class })
159    public void testLastNextNoHidden() throws NoSuchElementException
160    {
161  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al3);
162  5 while (it.hasNext())
163    {
164  4 it.next();
165    }
166  1 it.next();
167    }
168   
169    /*
170    * Test iterator always throws NoSuchElementException at end of iteration
171    * when alignment has hidden rows at start
172    */
 
173  1 toggle @Test(
174    groups = { "Functional" },
175    expectedExceptions = { NoSuchElementException.class })
176    public void testLastNextStartHidden() throws NoSuchElementException
177    {
178  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al2);
179  2 while (it.hasNext())
180    {
181  1 it.next();
182    }
183  1 it.next();
184    }
185   
186    /*
187    * Test iterator always throws NoSuchElementException at end of iteration
188    * when alignment has hidden rows at end
189    */
 
190  1 toggle @Test(
191    groups = { "Functional" },
192    expectedExceptions = { NoSuchElementException.class })
193    public void testLastNextEndHidden() throws NoSuchElementException
194    {
195  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 4, al);
196  3 while (it.hasNext())
197    {
198  2 it.next();
199    }
200  1 it.next();
201    }
202   
203    /*
204    * Test calls to remove throw UnsupportedOperationException
205    */
 
206  1 toggle @Test(
207    groups = { "Functional" },
208    expectedExceptions = { UnsupportedOperationException.class })
209    public void testRemove() throws UnsupportedOperationException
210    {
211  1 VisibleRowsIterator it = new VisibleRowsIterator(0, 3, al);
212  1 it.remove();
213    }
214   
215    /*
216    * Hide sequences between start and end
217    */
 
218  2 toggle private void hideSequences(AlignmentI alignment,
219    Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences,
220    int start, int end)
221    {
222  2 SequenceI[] allseqs = alignment.getSequencesArray();
223  2 SequenceGroup theseSeqs = new SequenceGroup();
224   
225  8 for (int i = start; i <= end; i++)
226    {
227  6 theseSeqs.addSequence(allseqs[i], false);
228  6 alignment.getHiddenSequences().hideSequence(allseqs[i]);
229    }
230   
231  2 hiddenRepSequences.put(allseqs[start], theseSeqs);
232    }
233    }