Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:12:26 GMT
  2. Package jalview.datamodel

File VisibleContigsIteratorTest.java

 

Code metrics

0
138
3
1
222
163
3
0.02
46
3
1

Classes

Class Line # Actions
VisibleContigsIteratorTest 32 138 3
1.0100%
 

Contributing tests

This file is covered by 3 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.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import java.util.ArrayList;
28    import java.util.List;
29   
30    import org.testng.annotations.Test;
31   
 
32    public class VisibleContigsIteratorTest
33    {
34    /**
35    * Test the iterator with single visible regions
36    */
 
37  1 toggle @Test(groups = { "Functional" })
38    public void testSimpleVisibleRegions()
39    {
40  1 List<int[]> hiddenColumns = null;
41   
42    // null hidden columns
43  1 VisibleContigsIterator it = new VisibleContigsIterator(3, 10,
44    hiddenColumns);
45  1 assertTrue(it.hasNext());
46  1 assertFalse(it.endsAtHidden());
47  1 int[] result = it.next();
48  1 assertEquals(3, result[0]);
49  1 assertEquals(9, result[1]);
50  1 assertFalse(it.hasNext());
51  1 assertFalse(it.endsAtHidden());
52   
53  1 hiddenColumns = new ArrayList<>();
54   
55    // no hidden columns
56  1 it = new VisibleContigsIterator(3, 10, hiddenColumns);
57  1 assertTrue(it.hasNext());
58  1 assertFalse(it.endsAtHidden());
59  1 result = it.next();
60  1 assertEquals(3, result[0]);
61  1 assertEquals(9, result[1]);
62  1 assertFalse(it.hasNext());
63  1 assertFalse(it.endsAtHidden());
64   
65    // hidden columns, but not where we are looking
66  1 hiddenColumns.add(new int[] { 5, 10 });
67  1 hiddenColumns.add(new int[] { 25, 40 });
68   
69  1 it = new VisibleContigsIterator(2, 3, hiddenColumns);
70  1 assertTrue(it.hasNext());
71  1 assertFalse(it.endsAtHidden());
72  1 result = it.next();
73  1 assertEquals(2, result[0]);
74  1 assertEquals(2, result[1]);
75  1 assertFalse(it.hasNext());
76  1 assertFalse(it.endsAtHidden());
77   
78  1 it = new VisibleContigsIterator(5, 7, hiddenColumns);
79  1 assertFalse(it.hasNext());
80  1 assertFalse(it.endsAtHidden());
81   
82  1 it = new VisibleContigsIterator(11, 15, hiddenColumns);
83  1 assertTrue(it.hasNext());
84  1 assertFalse(it.endsAtHidden());
85  1 result = it.next();
86  1 assertEquals(11, result[0]);
87  1 assertEquals(14, result[1]);
88  1 assertFalse(it.hasNext());
89  1 assertFalse(it.endsAtHidden());
90   
91  1 it = new VisibleContigsIterator(50, 60, hiddenColumns);
92  1 assertTrue(it.hasNext());
93  1 assertFalse(it.endsAtHidden());
94  1 result = it.next();
95  1 assertEquals(50, result[0]);
96  1 assertEquals(59, result[1]);
97  1 assertFalse(it.hasNext());
98  1 assertFalse(it.endsAtHidden());
99    }
100   
101    /**
102    * Test the iterator with multiple visible regions
103    */
 
104  1 toggle @Test(groups = { "Functional" })
105    public void testMultipleVisibleRegions()
106    {
107  1 List<int[]> hiddenColumns = new ArrayList<>();
108  1 hiddenColumns.add(new int[] { 5, 10 });
109  1 hiddenColumns.add(new int[] { 25, 40 });
110   
111    // all hidden columns covered
112  1 VisibleContigsIterator it = new VisibleContigsIterator(3, 50,
113    hiddenColumns);
114  1 assertTrue(it.hasNext());
115  1 assertFalse(it.endsAtHidden());
116  1 int[] result = it.next();
117  1 assertEquals(3, result[0]);
118  1 assertEquals(4, result[1]);
119   
120  1 assertTrue(it.hasNext());
121  1 assertFalse(it.endsAtHidden());
122  1 result = it.next();
123  1 assertEquals(11, result[0]);
124  1 assertEquals(24, result[1]);
125   
126  1 assertTrue(it.hasNext());
127  1 assertFalse(it.endsAtHidden());
128  1 result = it.next();
129  1 assertEquals(41, result[0]);
130  1 assertEquals(49, result[1]);
131   
132  1 assertFalse(it.hasNext());
133  1 assertFalse(it.endsAtHidden());
134    }
135   
136    /**
137    * Test the iterator with regions which start/end at hidden region edges
138    */
 
139  1 toggle @Test(groups = { "Functional" })
140    public void testVisibleRegionsAtHiddenEdges()
141    {
142  1 List<int[]> hiddenColumns = new ArrayList<>();
143  1 hiddenColumns.add(new int[] { 5, 10 });
144  1 hiddenColumns.add(new int[] { 25, 40 });
145   
146  1 VisibleContigsIterator it = new VisibleContigsIterator(0, 10,
147    hiddenColumns);
148  1 assertTrue(it.hasNext());
149  1 assertTrue(it.endsAtHidden());
150  1 int[] result = it.next();
151  1 assertEquals(0, result[0]);
152  1 assertEquals(4, result[1]);
153  1 assertFalse(it.hasNext());
154  1 assertTrue(it.endsAtHidden());
155   
156  1 it = new VisibleContigsIterator(2, 11, hiddenColumns);
157  1 assertTrue(it.hasNext());
158  1 assertTrue(it.endsAtHidden());
159  1 result = it.next();
160  1 assertEquals(2, result[0]);
161  1 assertEquals(4, result[1]);
162  1 assertFalse(it.hasNext());
163  1 assertTrue(it.endsAtHidden());
164   
165  1 it = new VisibleContigsIterator(2, 12, hiddenColumns);
166  1 assertTrue(it.hasNext());
167  1 assertFalse(it.endsAtHidden());
168  1 result = it.next();
169  1 assertEquals(2, result[0]);
170  1 assertEquals(4, result[1]);
171  1 assertTrue(it.hasNext());
172  1 assertFalse(it.endsAtHidden());
173  1 result = it.next();
174  1 assertEquals(11, result[0]);
175  1 assertEquals(11, result[1]);
176  1 assertFalse(it.hasNext());
177  1 assertFalse(it.endsAtHidden());
178   
179  1 it = new VisibleContigsIterator(13, 25, hiddenColumns);
180  1 assertTrue(it.hasNext());
181  1 assertFalse(it.endsAtHidden());
182  1 result = it.next();
183  1 assertEquals(13, result[0]);
184  1 assertEquals(24, result[1]);
185  1 assertFalse(it.hasNext());
186   
187  1 it = new VisibleContigsIterator(13, 26, hiddenColumns);
188  1 assertTrue(it.hasNext());
189  1 assertTrue(it.endsAtHidden());
190  1 result = it.next();
191  1 assertEquals(13, result[0]);
192  1 assertEquals(24, result[1]);
193  1 assertFalse(it.hasNext());
194   
195  1 it = new VisibleContigsIterator(13, 27, hiddenColumns);
196  1 assertTrue(it.hasNext());
197  1 assertTrue(it.endsAtHidden());
198  1 result = it.next();
199  1 assertEquals(13, result[0]);
200  1 assertEquals(24, result[1]);
201  1 assertFalse(it.hasNext());
202   
203  1 it = new VisibleContigsIterator(13, 41, hiddenColumns);
204  1 assertTrue(it.hasNext());
205  1 assertTrue(it.endsAtHidden());
206  1 result = it.next();
207  1 assertEquals(13, result[0]);
208  1 assertEquals(24, result[1]);
209  1 assertFalse(it.hasNext());
210   
211  1 it = new VisibleContigsIterator(13, 42, hiddenColumns);
212  1 assertTrue(it.hasNext());
213  1 assertFalse(it.endsAtHidden());
214  1 result = it.next();
215  1 assertEquals(13, result[0]);
216  1 assertEquals(24, result[1]);
217  1 assertTrue(it.hasNext());
218  1 result = it.next();
219  1 assertEquals(41, result[0]);
220  1 assertEquals(41, result[1]);
221    }
222    }