Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.datamodel

File AlignmentViewTest.java

 

Code metrics

0
55
4
1
149
94
4
0.07
13.75
4
1

Classes

Class Line # Actions
AlignmentViewTest 41 55 4
0.813559381.4%
 

Contributing tests

This file is covered by 2 tests. .

Source view

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.hamcrest.MatcherAssert.assertThat;
24    import static org.hamcrest.Matchers.contains;
25    import org.hamcrest.Matchers;
26    import static org.testng.Assert.assertEquals;
27   
28    import java.util.Arrays;
29    import java.util.List;
30   
31    import jalview.gui.AlignFrame;
32    import jalview.gui.JvOptionPane;
33    import jalview.io.DataSourceType;
34    import jalview.io.FileLoader;
35    import jalview.viewmodel.AlignmentViewport;
36   
37    import org.testng.annotations.BeforeClass;
38    import org.testng.annotations.Test;
39   
40   
 
41    public class AlignmentViewTest
42    {
43   
 
44  1 toggle @BeforeClass(alwaysRun = true)
45    public void setUpJvOptionPane()
46    {
47  1 JvOptionPane.setInteractiveMode(false);
48  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
49    }
50   
 
51  1 toggle @Test(groups = { "Functional" })
52    public void testGetVisibleAlignmentGapChar()
53    {
54  1 SeqCigar ss = new SeqCigar(new Sequence("One", "A..CDE"));
55  1 CigarArray ca = new CigarArray(new CigarSimple[] { ss });
56  1 AlignmentView av = new AlignmentView(ca);
57  1 String dots = av.getSequenceStrings('.')[0];
58  1 assertEquals(dots, "A..CDE");
59  1 String dollars = av.getSequenceStrings('$')[0];
60  1 assertEquals(dollars, "A$$CDE");
61  1 assertEquals(av.getVisibleAlignment('$').getSequenceAt(0)
62    .getSequenceAsString(), "A$$CDE");
63    }
64   
 
65  0 toggle @Test
66    public void testGetVisibleContigMapFor()
67    {
68  0 AlignFrame af = new FileLoader()
69    .LoadFileWaitTillLoaded(">seq\nAAA-AAAA---AA--\n",
70    DataSourceType.PASTE);
71  0 var av = af.getViewport();
72  0 var seq = av.getAlignment().getSequenceAt(0);
73  0 var gapMap = seq.gapMap();
74  0 assertThat(Arrays.stream(gapMap).boxed().toArray(Integer[]::new),
75    Matchers.arrayContaining(0, 1, 2, 4, 5, 6, 7, 11, 12));
76   
77  0 av.hideColumns(0, 1);
78  0 av.hideColumns(6, 7);
79  0 AlignmentView view = av.getAlignmentView(true);
80  0 var delMap = view.getVisibleContigMapFor(gapMap);
81  0 assertThat(Arrays.stream(delMap).boxed().toArray(Integer[]::new),
82    Matchers.arrayContaining(2, 3, 4, 7, 8));
83    }
84   
 
85  1 toggle @Test(groups = { "Functional" })
86    public void testGetVisibleContigs()
87    {
88  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
89    ">s1\n0123456789\n", DataSourceType.PASTE);
90  1 AlignmentViewport av = af.getViewport();
91  1 AlignmentView view = av.getAlignmentView(true);
92   
93    /*
94    * verify getVisibleContigs returns inclusive [start, end] ranges
95    *
96    * no columns hidden
97    */
98  1 int[] contigs = view.getVisibleContigs();
99  1 assertEquals(contigs, new int[] { 0, 9 });
100   
101    /*
102    * hide 3 internal columns
103    */
104  1 av.hideColumns(5, 7);
105    // the old AlignmentView is now stale!
106  1 contigs = view.getVisibleContigs();
107  1 assertEquals(contigs, new int[] { 0, 9 });
108    // get a fresh AlignmentView
109  1 view = av.getAlignmentView(true);
110  1 contigs = view.getVisibleContigs();
111  1 assertEquals(contigs, new int[] { 0, 4, 8, 9 });
112   
113    // hide first 2 columns
114  1 av.hideColumns(0, 1);
115  1 view = av.getAlignmentView(true);
116  1 contigs = view.getVisibleContigs();
117  1 assertEquals(contigs, new int[] { 2, 4, 8, 9 });
118   
119    // hide last column
120  1 av.hideColumns(9, 9);
121  1 view = av.getAlignmentView(true);
122  1 contigs = view.getVisibleContigs();
123  1 assertEquals(contigs, new int[] { 2, 4, 8, 8 });
124   
125    // unhide columns 5-7
126  1 av.showColumn(5);
127  1 view = av.getAlignmentView(true);
128  1 contigs = view.getVisibleContigs();
129  1 assertEquals(contigs, new int[] { 2, 8 });
130   
131    // hide columns 2-7
132  1 av.hideColumns(2, 7);
133  1 view = av.getAlignmentView(true);
134  1 contigs = view.getVisibleContigs();
135  1 assertEquals(contigs, new int[] { 8, 8 });
136   
137    // hide column 8
138  1 av.hideColumns(8, 8);
139  1 view = av.getAlignmentView(true);
140  1 contigs = view.getVisibleContigs();
141  1 assertEquals(contigs, new int[] {});
142   
143    // unhide all
144  1 av.showAllHiddenColumns();
145  1 view = av.getAlignmentView(true);
146  1 contigs = view.getVisibleContigs();
147  1 assertEquals(contigs, new int[] { 0, 9 });
148    }
149    }