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.assertEquals;
25 import jalview.gui.AlignFrame;
26 import jalview.gui.AlignViewport;
27 import jalview.gui.JvOptionPane;
28 import jalview.io.DataSourceType;
29 import jalview.io.FileLoader;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.Test;
34 public class AlignmentViewTest
37 @BeforeClass(alwaysRun = true)
38 public void setUpJvOptionPane()
40 JvOptionPane.setInteractiveMode(false);
41 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
44 @Test(groups = { "Functional" })
45 public void testGetVisibleAlignmentGapChar()
47 SeqCigar ss = new SeqCigar(new Sequence("One", "A..CDE"));
48 CigarArray ca = new CigarArray(new CigarSimple[] { ss });
49 AlignmentView av = new AlignmentView(ca);
50 String dots = av.getSequenceStrings('.')[0];
51 assertEquals(dots, "A..CDE");
52 String dollars = av.getSequenceStrings('$')[0];
53 assertEquals(dollars, "A$$CDE");
54 assertEquals(av.getVisibleAlignment('$').getSequenceAt(0)
55 .getSequenceAsString(), "A$$CDE");
58 @Test(groups = { "Functional" })
59 public void testGetVisibleContigs()
61 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
62 ">s1\n0123456789\n", DataSourceType.PASTE);
63 AlignViewport av = af.getViewport();
64 AlignmentView view = av.getAlignmentView(true);
67 * verify getVisibleContigs returns inclusive [start, end] ranges
71 int[] contigs = view.getVisibleContigs();
72 assertEquals(contigs, new int[] { 0, 9 });
75 * hide 3 internal columns
78 // the old AlignmentView is now stale!
79 contigs = view.getVisibleContigs();
80 assertEquals(contigs, new int[] { 0, 9 });
81 // get a fresh AlignmentView
82 view = av.getAlignmentView(true);
83 contigs = view.getVisibleContigs();
84 assertEquals(contigs, new int[] { 0, 4, 8, 9 });
86 // hide first 2 columns
88 view = av.getAlignmentView(true);
89 contigs = view.getVisibleContigs();
90 assertEquals(contigs, new int[] { 2, 4, 8, 9 });
94 view = av.getAlignmentView(true);
95 contigs = view.getVisibleContigs();
96 assertEquals(contigs, new int[] { 2, 4, 8, 8 });
100 view = av.getAlignmentView(true);
101 contigs = view.getVisibleContigs();
102 assertEquals(contigs, new int[] { 2, 8 });
105 av.hideColumns(2, 7);
106 view = av.getAlignmentView(true);
107 contigs = view.getVisibleContigs();
108 assertEquals(contigs, new int[] { 8, 8 });
111 av.hideColumns(8, 8);
112 view = av.getAlignmentView(true);
113 contigs = view.getVisibleContigs();
114 assertEquals(contigs, new int[] {});
117 av.showAllHiddenColumns();
118 view = av.getAlignmentView(true);
119 contigs = view.getVisibleContigs();
120 assertEquals(contigs, new int[] { 0, 9 });