Clover icon

jalviewX

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

File StartRegionIteratorTest.java

 

Code metrics

0
118
3
1
214
144
3
0.03
39.33
3
1

Classes

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