2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.datamodel;
23 import static org.testng.Assert.assertNull;
24 import static org.testng.AssertJUnit.assertEquals;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.testng.annotations.Test;
31 public class HiddenColumnsCursorTest
34 @Test(groups = { "Functional" })
35 public void testConstructor()
37 HiddenColumnsCursor cursor = new HiddenColumnsCursor();
38 assertNull(cursor.findRegionForColumn(0, false));
40 List<int[]> hlist = new ArrayList<>();
41 cursor = new HiddenColumnsCursor(hlist);
42 assertNull(cursor.findRegionForColumn(0, false));
44 cursor = new HiddenColumnsCursor(hlist, 3, 12);
45 assertNull(cursor.findRegionForColumn(0, false));
47 hlist.add(new int[] { 3, 7 });
48 hlist.add(new int[] { 15, 25 });
49 cursor = new HiddenColumnsCursor(hlist);
50 HiddenCursorPosition p = cursor.findRegionForColumn(8, false);
51 assertEquals(1, p.getRegionIndex());
53 cursor = new HiddenColumnsCursor(hlist, 1, 5);
54 p = cursor.findRegionForColumn(8, false);
55 assertEquals(1, p.getRegionIndex());
59 * Test the method which finds the corresponding region given a column
61 @Test(groups = { "Functional" })
62 public void testFindRegionForColumn()
64 HiddenColumnsCursor cursor = new HiddenColumnsCursor();
66 HiddenCursorPosition pos = cursor.findRegionForColumn(20, false);
69 List<int[]> hidden = new ArrayList<>();
70 hidden.add(new int[] { 53, 76 });
71 hidden.add(new int[] { 104, 125 });
73 cursor = new HiddenColumnsCursor(hidden);
75 int regionIndex = cursor.findRegionForColumn(126, false)
77 assertEquals(2, regionIndex);
79 regionIndex = cursor.findRegionForColumn(125, false).getRegionIndex();
80 assertEquals(1, regionIndex);
82 regionIndex = cursor.findRegionForColumn(108, false).getRegionIndex();
83 assertEquals(1, regionIndex);
85 regionIndex = cursor.findRegionForColumn(104, false).getRegionIndex();
86 assertEquals(1, regionIndex);
88 regionIndex = cursor.findRegionForColumn(103, false).getRegionIndex();
89 assertEquals(1, regionIndex);
91 regionIndex = cursor.findRegionForColumn(77, false).getRegionIndex();
92 assertEquals(1, regionIndex);
94 regionIndex = cursor.findRegionForColumn(76, false).getRegionIndex();
95 assertEquals(0, regionIndex);
97 regionIndex = cursor.findRegionForColumn(53, false).getRegionIndex();
98 assertEquals(0, regionIndex);
100 regionIndex = cursor.findRegionForColumn(52, false).getRegionIndex();
101 assertEquals(0, regionIndex);
103 regionIndex = cursor.findRegionForColumn(0, false).getRegionIndex();
104 assertEquals(0, regionIndex);
106 hidden.add(new int[] { 138, 155 });
108 cursor = new HiddenColumnsCursor(hidden);
110 regionIndex = cursor.findRegionForColumn(160, false).getRegionIndex();
111 assertEquals(3, regionIndex);
113 regionIndex = cursor.findRegionForColumn(100, false).getRegionIndex();
114 assertEquals(1, regionIndex);
118 * Test the method which counts the number of hidden columns before a column
120 @Test(groups = { "Functional" })
121 public void testFindRegionForColumn_Visible()
123 HiddenColumnsCursor cursor = new HiddenColumnsCursor();
125 HiddenCursorPosition pos = cursor.findRegionForColumn(20, true);
128 List<int[]> hidden = new ArrayList<>();
129 hidden.add(new int[] { 53, 76 });
130 hidden.add(new int[] { 104, 125 });
132 cursor = new HiddenColumnsCursor(hidden);
134 int offset = cursor.findRegionForColumn(80, true).getHiddenSoFar();
135 assertEquals(46, offset);
137 offset = cursor.findRegionForColumn(79, true).getHiddenSoFar();
138 assertEquals(24, offset);
140 offset = cursor.findRegionForColumn(53, true).getHiddenSoFar();
141 assertEquals(24, offset);
143 offset = cursor.findRegionForColumn(52, true).getHiddenSoFar();
144 assertEquals(0, offset);
146 offset = cursor.findRegionForColumn(10, true).getHiddenSoFar();
147 assertEquals(0, offset);
149 offset = cursor.findRegionForColumn(0, true).getHiddenSoFar();
150 assertEquals(0, offset);
152 offset = cursor.findRegionForColumn(79, true).getHiddenSoFar();
153 assertEquals(24, offset);
155 offset = cursor.findRegionForColumn(80, true).getHiddenSoFar();
156 assertEquals(46, offset);