Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 11:45:30 GMT
  2. Package jalview.datamodel

File StartRegionIteratorTest.java

 

Code metrics

0
118
3
1
213
143
3
0.03
39.33
3
1

Classes

Class Line # Actions
StartRegionIteratorTest 33 118 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.Iterator;
29    import java.util.List;
30   
31    import org.testng.annotations.Test;
32   
 
33    public class StartRegionIteratorTest
34    {
35    /**
36    * Test the start region iterator
37    */
 
38  1 toggle @Test(groups = { "Functional" })
39    public void testBasicBoundsIterator()
40    {
41  1 List<int[]> hiddenColumns = null;
42   
43    // null hidden columns
44  1 Iterator<Integer> it = new StartRegionIterator(3, 10, hiddenColumns);
45  1 assertFalse(it.hasNext());
46   
47  1 hiddenColumns = new ArrayList<>();
48   
49    // no hidden columns
50  1 it = new StartRegionIterator(3, 10, hiddenColumns);
51  1 assertFalse(it.hasNext());
52   
53    // add some hidden columns
54  1 hiddenColumns.add(new int[] { 5, 10 });
55  1 hiddenColumns.add(new int[] { 25, 40 });
56   
57  1 it = new StartRegionIterator(3, 10, hiddenColumns);
58  1 assertTrue(it.hasNext());
59  1 Integer result = it.next();
60  1 assertEquals(5, (int) result);
61  1 assertFalse(it.hasNext());
62   
63  1 it = new StartRegionIterator(3, 15, hiddenColumns);
64  1 assertTrue(it.hasNext());
65  1 result = it.next();
66  1 assertEquals(5, (int) result);
67  1 assertFalse(it.hasNext());
68   
69  1 it = new StartRegionIterator(3, 18, hiddenColumns);
70  1 assertTrue(it.hasNext());
71  1 result = it.next();
72  1 assertEquals(5, (int) result);
73  1 assertFalse(it.hasNext());
74   
75  1 it = new StartRegionIterator(3, 19, hiddenColumns);
76  1 assertTrue(it.hasNext());
77  1 result = it.next();
78  1 assertEquals(5, (int) result);
79  1 assertTrue(it.hasNext());
80  1 result = it.next();
81  1 assertEquals(19, (int) result);
82  1 assertFalse(it.hasNext());
83   
84  1 hiddenColumns.add(new int[] { 47, 50 });
85   
86  1 it = new StartRegionIterator(15, 60, hiddenColumns);
87  1 assertTrue(it.hasNext());
88  1 result = it.next();
89  1 assertEquals(19, (int) result);
90  1 assertTrue(it.hasNext());
91  1 result = it.next();
92  1 assertEquals(25, (int) result);
93  1 assertFalse(it.hasNext());
94    }
95   
96    /**
97    * Test the start region iterator with null cursor
98    */
 
99  1 toggle @Test(groups = { "Functional" })
100    public void testBoundsIteratorUsingNullCursor()
101    {
102  1 List<int[]> hiddenColumns = null;
103  1 HiddenCursorPosition pos = null;
104   
105    // null hidden columns
106  1 Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
107    hiddenColumns);
108  1 assertFalse(it.hasNext());
109   
110  1 hiddenColumns = new ArrayList<>();
111   
112    // no hidden columns
113  1 it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
114  1 assertFalse(it.hasNext());
115   
116    // add some hidden columns
117  1 hiddenColumns.add(new int[] { 5, 10 });
118  1 hiddenColumns.add(new int[] { 25, 40 });
119   
120  1 it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
121  1 assertTrue(it.hasNext());
122  1 Integer result = it.next();
123  1 assertEquals(5, (int) result);
124  1 assertFalse(it.hasNext());
125   
126  1 it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
127  1 assertTrue(it.hasNext());
128  1 result = it.next();
129  1 assertEquals(5, (int) result);
130  1 assertFalse(it.hasNext());
131   
132  1 it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
133  1 assertTrue(it.hasNext());
134  1 result = it.next();
135  1 assertEquals(5, (int) result);
136  1 assertFalse(it.hasNext());
137   
138  1 it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
139  1 assertTrue(it.hasNext());
140  1 result = it.next();
141  1 assertEquals(5, (int) result);
142  1 assertTrue(it.hasNext());
143  1 result = it.next();
144  1 assertEquals(19, (int) result);
145  1 assertFalse(it.hasNext());
146   
147  1 hiddenColumns.add(new int[] { 47, 50 });
148   
149  1 it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
150  1 assertTrue(it.hasNext());
151  1 result = it.next();
152  1 assertEquals(19, (int) result);
153  1 assertTrue(it.hasNext());
154  1 result = it.next();
155  1 assertEquals(25, (int) result);
156  1 assertFalse(it.hasNext());
157    }
158   
159    /**
160    * Test the start region iterator with nonnull cursor
161    */
 
162  1 toggle @Test(groups = { "Functional" })
163    public void testBoundsIteratorUsingCursor()
164    {
165  1 List<int[]> hiddenColumns = new ArrayList<>();
166   
167    // add some hidden columns
168  1 hiddenColumns.add(new int[] { 5, 10 });
169  1 hiddenColumns.add(new int[] { 25, 40 });
170   
171  1 HiddenCursorPosition pos = new HiddenCursorPosition(0, 0);
172   
173  1 Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
174    hiddenColumns);
175  1 assertTrue(it.hasNext());
176  1 Integer result = it.next();
177  1 assertEquals(5, (int) result);
178  1 assertFalse(it.hasNext());
179   
180  1 it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
181  1 assertTrue(it.hasNext());
182  1 result = it.next();
183  1 assertEquals(5, (int) result);
184  1 assertFalse(it.hasNext());
185   
186  1 it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
187  1 assertTrue(it.hasNext());
188  1 result = it.next();
189  1 assertEquals(5, (int) result);
190  1 assertFalse(it.hasNext());
191   
192  1 it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
193  1 assertTrue(it.hasNext());
194  1 result = it.next();
195  1 assertEquals(5, (int) result);
196  1 assertTrue(it.hasNext());
197  1 result = it.next();
198  1 assertEquals(19, (int) result);
199  1 assertFalse(it.hasNext());
200   
201  1 pos = new HiddenCursorPosition(1, 6);
202  1 hiddenColumns.add(new int[] { 47, 50 });
203   
204  1 it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
205  1 assertTrue(it.hasNext());
206  1 result = it.next();
207  1 assertEquals(19, (int) result);
208  1 assertTrue(it.hasNext());
209  1 result = it.next();
210  1 assertEquals(25, (int) result);
211  1 assertFalse(it.hasNext());
212    }
213    }