Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / test / jalview / datamodel / AlignmentViewTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ 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.Assert.assertEquals;
24
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;
30
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.Test;
33
34 public class AlignmentViewTest
35 {
36
37   @BeforeClass(alwaysRun = true)
38   public void setUpJvOptionPane()
39   {
40     JvOptionPane.setInteractiveMode(false);
41     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
42   }
43
44   @Test(groups = { "Functional" })
45   public void testGetVisibleAlignmentGapChar()
46   {
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");
56   }
57
58   @Test(groups = { "Functional" })
59   public void testGetVisibleContigs()
60   {
61     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
62             ">s1\n0123456789\n", DataSourceType.PASTE);
63     AlignViewport av = af.getViewport();
64     AlignmentView view = av.getAlignmentView(true);
65
66     /*
67      * verify getVisibleContigs returns inclusive [start, end] ranges
68      * 
69      * no columns hidden
70      */
71     int[] contigs = view.getVisibleContigs();
72     assertEquals(contigs, new int[] { 0, 9 });
73
74     /*
75      * hide 3 internal columns
76      */
77     av.hideColumns(5, 7);
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 });
85
86     // hide first 2 columns
87     av.hideColumns(0, 1);
88     view = av.getAlignmentView(true);
89     contigs = view.getVisibleContigs();
90     assertEquals(contigs, new int[] { 2, 4, 8, 9 });
91
92     // hide last column
93     av.hideColumns(9, 9);
94     view = av.getAlignmentView(true);
95     contigs = view.getVisibleContigs();
96     assertEquals(contigs, new int[] { 2, 4, 8, 8 });
97
98     // unhide columns 5-7
99     av.showColumn(5);
100     view = av.getAlignmentView(true);
101     contigs = view.getVisibleContigs();
102     assertEquals(contigs, new int[] { 2, 8 });
103
104     // hide columns 2-7
105     av.hideColumns(2, 7);
106     view = av.getAlignmentView(true);
107     contigs = view.getVisibleContigs();
108     assertEquals(contigs, new int[] { 8, 8 });
109
110     // hide column 8
111     av.hideColumns(8, 8);
112     view = av.getAlignmentView(true);
113     contigs = view.getVisibleContigs();
114     assertEquals(contigs, new int[] {});
115
116     // unhide all
117     av.showAllHiddenColumns();
118     view = av.getAlignmentView(true);
119     contigs = view.getVisibleContigs();
120     assertEquals(contigs, new int[] { 0, 9 });
121   }
122 }