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 the method which finds the corresponding region given a column
36 @Test(groups = { "Functional" })
37 public void testFindRegionForColumn()
39 HiddenColumnsCursor cursor = new HiddenColumnsCursor();
41 HiddenCursorPosition pos = cursor.findRegionForColumn(20, false);
44 List<int[]> hidden = new ArrayList<>();
45 hidden.add(new int[] { 53, 76 });
46 hidden.add(new int[] { 104, 125 });
48 cursor = new HiddenColumnsCursor(hidden);
50 int regionIndex = cursor.findRegionForColumn(126, false).getRegionIndex();
51 assertEquals(2, regionIndex);
53 regionIndex = cursor.findRegionForColumn(125, false).getRegionIndex();
54 assertEquals(1, regionIndex);
56 regionIndex = cursor.findRegionForColumn(108, false).getRegionIndex();
57 assertEquals(1, regionIndex);
59 regionIndex = cursor.findRegionForColumn(104, false).getRegionIndex();
60 assertEquals(1, regionIndex);
62 regionIndex = cursor.findRegionForColumn(103, false).getRegionIndex();
63 assertEquals(1, regionIndex);
65 regionIndex = cursor.findRegionForColumn(77, false).getRegionIndex();
66 assertEquals(1, regionIndex);
68 regionIndex = cursor.findRegionForColumn(76, false).getRegionIndex();
69 assertEquals(0, regionIndex);
71 regionIndex = cursor.findRegionForColumn(53, false).getRegionIndex();
72 assertEquals(0, regionIndex);
74 regionIndex = cursor.findRegionForColumn(52, false).getRegionIndex();
75 assertEquals(0, regionIndex);
77 regionIndex = cursor.findRegionForColumn(0, false).getRegionIndex();
78 assertEquals(0, regionIndex);
80 hidden.add(new int[] { 138, 155 });
82 cursor = new HiddenColumnsCursor(hidden);
84 regionIndex = cursor.findRegionForColumn(160, false).getRegionIndex();
85 assertEquals(3, regionIndex);
87 regionIndex = cursor.findRegionForColumn(100, false).getRegionIndex();
88 assertEquals(1, regionIndex);
92 * Test the method which counts the number of hidden columns before a column
94 @Test(groups = { "Functional" })
95 public void testGetHiddenOffset()
97 HiddenColumnsCursor cursor = new HiddenColumnsCursor();
99 HiddenCursorPosition pos = cursor.findRegionForColumn(20, true);
102 List<int[]> hidden = new ArrayList<>();
103 hidden.add(new int[] { 53, 76 });
104 hidden.add(new int[] { 104, 125 });
106 cursor = new HiddenColumnsCursor(hidden);
108 int offset = cursor.findRegionForColumn(80, true).getHiddenSoFar();
109 assertEquals(46, offset);
111 offset = cursor.findRegionForColumn(79, true).getHiddenSoFar();
112 assertEquals(24, offset);
114 offset = cursor.findRegionForColumn(53, true).getHiddenSoFar();
115 assertEquals(24, offset);
117 offset = cursor.findRegionForColumn(52, true).getHiddenSoFar();
118 assertEquals(0, offset);
120 offset = cursor.findRegionForColumn(10, true).getHiddenSoFar();
121 assertEquals(0, offset);
123 offset = cursor.findRegionForColumn(0, true).getHiddenSoFar();
124 assertEquals(0, offset);
126 offset = cursor.findRegionForColumn(79, true).getHiddenSoFar();
127 assertEquals(24, offset);
129 offset = cursor.findRegionForColumn(80, true).getHiddenSoFar();
130 assertEquals(46, offset);