/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.datamodel; import static org.testng.AssertJUnit.assertEquals; import java.util.List; import org.testng.annotations.Test; public class ColumnSelectionTest { @Test(groups = { "Functional" }) public void testAddElement() { ColumnSelection cs = new ColumnSelection(); cs.addElement(2); cs.addElement(5); List sel = cs.getSelected(); assertEquals(2, sel.size()); assertEquals(new Integer(2), sel.get(0)); assertEquals(new Integer(5), sel.get(1)); } /** * Test the remove method - in particular to verify that remove(int i) removes * the element whose value is i, _NOT_ the i'th element. */ @Test(groups = { "Functional" }) public void testRemoveElement() { ColumnSelection cs = new ColumnSelection(); cs.addElement(2); cs.addElement(5); // removing elements not in the list has no effect cs.removeElement(0); cs.removeElement(1); List sel = cs.getSelected(); assertEquals(2, sel.size()); assertEquals(new Integer(2), sel.get(0)); assertEquals(new Integer(5), sel.get(1)); // removing an element in the list removes it cs.removeElement(2); assertEquals(1, sel.size()); assertEquals(new Integer(5), sel.get(0)); } /** * Test the method that finds the visible column position of an alignment * column, allowing for hidden columns. */ @Test(groups = { "Functional" }) public void testFindColumnPosition() { ColumnSelection cs = new ColumnSelection(); assertEquals(5, cs.findColumnPosition(5)); // hiding column 6 makes no difference cs.hideColumns(6, 6); assertEquals(5, cs.findColumnPosition(5)); // hiding column 5 makes no difference cs.hideColumns(5, 5); assertEquals(5, cs.findColumnPosition(5)); // hiding column 4 moves column 5 to column 4 cs.hideColumns(4, 4); assertEquals(4, cs.findColumnPosition(5)); // hiding columns 1 and 2 moves column 5 to column 2 cs.hideColumns(1, 2); assertEquals(2, cs.findColumnPosition(5)); } }