JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / test / jalview / datamodel / ColumnSelectionTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 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.AssertJUnit.assertEquals;
24
25 import java.util.List;
26
27 import org.testng.annotations.Test;
28
29 public class ColumnSelectionTest
30 {
31
32   @Test(groups = { "Functional" })
33   public void testAddElement()
34   {
35     ColumnSelection cs = new ColumnSelection();
36     cs.addElement(2);
37     cs.addElement(5);
38     List<Integer> sel = cs.getSelected();
39     assertEquals(2, sel.size());
40     assertEquals(new Integer(2), sel.get(0));
41     assertEquals(new Integer(5), sel.get(1));
42   }
43
44   /**
45    * Test the remove method - in particular to verify that remove(int i) removes
46    * the element whose value is i, _NOT_ the i'th element.
47    */
48   @Test(groups = { "Functional" })
49   public void testRemoveElement()
50   {
51     ColumnSelection cs = new ColumnSelection();
52     cs.addElement(2);
53     cs.addElement(5);
54
55     // removing elements not in the list has no effect
56     cs.removeElement(0);
57     cs.removeElement(1);
58     List<Integer> sel = cs.getSelected();
59     assertEquals(2, sel.size());
60     assertEquals(new Integer(2), sel.get(0));
61     assertEquals(new Integer(5), sel.get(1));
62
63     // removing an element in the list removes it
64     cs.removeElement(2);
65     assertEquals(1, sel.size());
66     assertEquals(new Integer(5), sel.get(0));
67   }
68
69   /**
70    * Test the method that finds the visible column position of an alignment
71    * column, allowing for hidden columns.
72    */
73   @Test(groups = { "Functional" })
74   public void testFindColumnPosition()
75   {
76     ColumnSelection cs = new ColumnSelection();
77     assertEquals(5, cs.findColumnPosition(5));
78
79     // hiding column 6 makes no difference
80     cs.hideColumns(6, 6);
81     assertEquals(5, cs.findColumnPosition(5));
82
83     // hiding column 5 makes no difference
84     cs.hideColumns(5, 5);
85     assertEquals(5, cs.findColumnPosition(5));
86
87     // hiding column 4 moves column 5 to column 4
88     cs.hideColumns(4, 4);
89     assertEquals(4, cs.findColumnPosition(5));
90
91     // hiding columns 1 and 2 moves column 5 to column 2
92     cs.hideColumns(1, 2);
93     assertEquals(2, cs.findColumnPosition(5));
94   }
95 }