Clover icon

jalviewX

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

File HiddenColumnsCursorTest.java

 

Code metrics

0
71
3
1
157
92
3
0.04
23.67
3
1

Classes

Class Line # Actions
HiddenColumnsCursorTest 31 71 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.assertNull;
24    import static org.testng.AssertJUnit.assertEquals;
25   
26    import java.util.ArrayList;
27    import java.util.List;
28   
29    import org.testng.annotations.Test;
30   
 
31    public class HiddenColumnsCursorTest
32    {
33   
 
34  1 toggle @Test(groups = { "Functional" })
35    public void testConstructor()
36    {
37  1 HiddenColumnsCursor cursor = new HiddenColumnsCursor();
38  1 assertNull(cursor.findRegionForColumn(0, false));
39   
40  1 List<int[]> hlist = new ArrayList<>();
41  1 cursor = new HiddenColumnsCursor(hlist);
42  1 assertNull(cursor.findRegionForColumn(0, false));
43   
44  1 cursor = new HiddenColumnsCursor(hlist, 3, 12);
45  1 assertNull(cursor.findRegionForColumn(0, false));
46   
47  1 hlist.add(new int[] { 3, 7 });
48  1 hlist.add(new int[] { 15, 25 });
49  1 cursor = new HiddenColumnsCursor(hlist);
50  1 HiddenCursorPosition p = cursor.findRegionForColumn(8, false);
51  1 assertEquals(1, p.getRegionIndex());
52   
53  1 cursor = new HiddenColumnsCursor(hlist, 1, 5);
54  1 p = cursor.findRegionForColumn(8, false);
55  1 assertEquals(1, p.getRegionIndex());
56    }
57   
58    /**
59    * Test the method which finds the corresponding region given a column
60    */
 
61  1 toggle @Test(groups = { "Functional" })
62    public void testFindRegionForColumn()
63    {
64  1 HiddenColumnsCursor cursor = new HiddenColumnsCursor();
65   
66  1 HiddenCursorPosition pos = cursor.findRegionForColumn(20, false);
67  1 assertNull(pos);
68   
69  1 List<int[]> hidden = new ArrayList<>();
70  1 hidden.add(new int[] { 53, 76 });
71  1 hidden.add(new int[] { 104, 125 });
72   
73  1 cursor = new HiddenColumnsCursor(hidden);
74   
75  1 int regionIndex = cursor.findRegionForColumn(126, false).getRegionIndex();
76  1 assertEquals(2, regionIndex);
77   
78  1 regionIndex = cursor.findRegionForColumn(125, false).getRegionIndex();
79  1 assertEquals(1, regionIndex);
80   
81  1 regionIndex = cursor.findRegionForColumn(108, false).getRegionIndex();
82  1 assertEquals(1, regionIndex);
83   
84  1 regionIndex = cursor.findRegionForColumn(104, false).getRegionIndex();
85  1 assertEquals(1, regionIndex);
86   
87  1 regionIndex = cursor.findRegionForColumn(103, false).getRegionIndex();
88  1 assertEquals(1, regionIndex);
89   
90  1 regionIndex = cursor.findRegionForColumn(77, false).getRegionIndex();
91  1 assertEquals(1, regionIndex);
92   
93  1 regionIndex = cursor.findRegionForColumn(76, false).getRegionIndex();
94  1 assertEquals(0, regionIndex);
95   
96  1 regionIndex = cursor.findRegionForColumn(53, false).getRegionIndex();
97  1 assertEquals(0, regionIndex);
98   
99  1 regionIndex = cursor.findRegionForColumn(52, false).getRegionIndex();
100  1 assertEquals(0, regionIndex);
101   
102  1 regionIndex = cursor.findRegionForColumn(0, false).getRegionIndex();
103  1 assertEquals(0, regionIndex);
104   
105  1 hidden.add(new int[] { 138, 155 });
106   
107  1 cursor = new HiddenColumnsCursor(hidden);
108   
109  1 regionIndex = cursor.findRegionForColumn(160, false).getRegionIndex();
110  1 assertEquals(3, regionIndex);
111   
112  1 regionIndex = cursor.findRegionForColumn(100, false).getRegionIndex();
113  1 assertEquals(1, regionIndex);
114    }
115   
116    /**
117    * Test the method which counts the number of hidden columns before a column
118    */
 
119  1 toggle @Test(groups = { "Functional" })
120    public void testFindRegionForColumn_Visible()
121    {
122  1 HiddenColumnsCursor cursor = new HiddenColumnsCursor();
123   
124  1 HiddenCursorPosition pos = cursor.findRegionForColumn(20, true);
125  1 assertNull(pos);
126   
127  1 List<int[]> hidden = new ArrayList<>();
128  1 hidden.add(new int[] { 53, 76 });
129  1 hidden.add(new int[] { 104, 125 });
130   
131  1 cursor = new HiddenColumnsCursor(hidden);
132   
133  1 int offset = cursor.findRegionForColumn(80, true).getHiddenSoFar();
134  1 assertEquals(46, offset);
135   
136  1 offset = cursor.findRegionForColumn(79, true).getHiddenSoFar();
137  1 assertEquals(24, offset);
138   
139  1 offset = cursor.findRegionForColumn(53, true).getHiddenSoFar();
140  1 assertEquals(24, offset);
141   
142  1 offset = cursor.findRegionForColumn(52, true).getHiddenSoFar();
143  1 assertEquals(0, offset);
144   
145  1 offset = cursor.findRegionForColumn(10, true).getHiddenSoFar();
146  1 assertEquals(0, offset);
147   
148  1 offset = cursor.findRegionForColumn(0, true).getHiddenSoFar();
149  1 assertEquals(0, offset);
150   
151  1 offset = cursor.findRegionForColumn(79, true).getHiddenSoFar();
152  1 assertEquals(24, offset);
153   
154  1 offset = cursor.findRegionForColumn(80, true).getHiddenSoFar();
155  1 assertEquals(46, offset);
156    }
157    }