Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 18:27:33 GMT
  2. Package jalview.renderer

File ResidueColourFinderTest.java

 

Code metrics

2
40
4
1
142
90
5
0.12
10
4
1.25

Classes

Class Line # Actions
ResidueColourFinderTest 39 40 5
1.0100%
 

Contributing tests

This file is covered by 3 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.renderer;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24   
25    import jalview.datamodel.Alignment;
26    import jalview.datamodel.AlignmentI;
27    import jalview.datamodel.Sequence;
28    import jalview.datamodel.SequenceI;
29    import jalview.gui.AlignViewport;
30    import jalview.gui.JvOptionPane;
31    import jalview.schemes.UserColourScheme;
32    import jalview.schemes.ZappoColourScheme;
33   
34    import java.awt.Color;
35   
36    import org.testng.annotations.BeforeClass;
37    import org.testng.annotations.Test;
38   
 
39    public class ResidueColourFinderTest
40    {
41   
 
42  1 toggle @BeforeClass(alwaysRun = true)
43    public void setUpJvOptionPane()
44    {
45  1 JvOptionPane.setInteractiveMode(false);
46  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
47    }
48   
 
49  1 toggle @Test(groups = { "Functional" })
50    public void testGetResidueColour_zappo()
51    {
52  1 SequenceI seq = new Sequence("name", "MATVLGSPRAPAFF"); // FER1_MAIZE...
53  1 AlignmentI al = new Alignment(new SequenceI[] { seq });
54  1 final AlignViewport av = new AlignViewport(al);
55  1 ResidueColourFinder rcf = new ResidueColourFinder();
56  1 av.setGlobalColourScheme(new ZappoColourScheme());
57   
58    // @see ResidueProperties.zappo
59  1 assertEquals(Color.pink, rcf.getResidueColour(true,
60    av.getResidueShading(), null, seq, 0, null)); // M
61  1 assertEquals(Color.green, rcf.getResidueColour(true,
62    av.getResidueShading(), null, seq, 2, null)); // T
63  1 assertEquals(Color.magenta, rcf.getResidueColour(true,
64    av.getResidueShading(), null, seq, 5, null)); // G
65  1 assertEquals(Color.orange, rcf.getResidueColour(true,
66    av.getResidueShading(), null, seq, 12, null)); // F
67   
68    // everything is white if showBoxes is false
69  1 assertEquals(Color.white, rcf.getResidueColour(false,
70    av.getResidueShading(), null, seq, 0, null)); // M
71  1 assertEquals(Color.white, rcf.getResidueColour(false,
72    av.getResidueShading(), null, seq, 2, null)); // T
73  1 assertEquals(Color.white, rcf.getResidueColour(false,
74    av.getResidueShading(), null, seq, 5, null)); // G
75  1 assertEquals(Color.white, rcf.getResidueColour(false,
76    av.getResidueShading(), null, seq, 12, null)); // F
77    }
78   
 
79  1 toggle @Test(groups = { "Functional" })
80    public void testGetResidueColour_none()
81    {
82  1 SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
83  1 AlignmentI al = new Alignment(new SequenceI[] { seq });
84  1 final AlignViewport av = new AlignViewport(al);
85  1 ResidueColourFinder rcf = new ResidueColourFinder();
86   
87  1 assertEquals(Color.white, rcf.getResidueColour(true,
88    av.getResidueShading(), null, seq, 0, null));
89  1 assertEquals(Color.white, rcf.getResidueColour(true,
90    av.getResidueShading(), null, seq, 2, null));
91   
92    // no change if showBoxes is false
93  1 assertEquals(Color.white, rcf.getResidueColour(false,
94    av.getResidueShading(), null, seq, 0, null));
95  1 assertEquals(Color.white, rcf.getResidueColour(false,
96    av.getResidueShading(), null, seq, 2, null));
97    }
98   
 
99  1 toggle @Test(groups = { "Functional" })
100    public void testGetResidueColour_userdef()
101    {
102  1 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
103    // gap
104  1 AlignmentI al = new Alignment(new SequenceI[] { seq });
105  1 final AlignViewport av = new AlignViewport(al);
106  1 ResidueColourFinder rcf = new ResidueColourFinder();
107   
108  1 Color[] newColours = new Color[24];
109  25 for (int i = 0; i < 24; i++)
110    {
111  24 newColours[i] = null;
112    }
113   
114  1 av.setGlobalColourScheme(new UserColourScheme(newColours));
115   
116    // gap colour not specified so gap colour is null
117    // this is consistent with previous behaviour, but may not be correct?
118  1 assertEquals(null, rcf.getResidueColour(true, av.getResidueShading(),
119    null, seq, 3, null));
120   
121  1 newColours[23] = Color.pink;
122  1 av.setGlobalColourScheme(new UserColourScheme(newColours));
123   
124    // gap colour specified as pink
125  1 assertEquals(Color.pink, rcf.getResidueColour(true,
126    av.getResidueShading(), null, seq, 3, null));
127   
128    // everything is white if showBoxes is false
129  1 newColours[23] = null;
130  1 assertEquals(Color.white, rcf.getResidueColour(false,
131    av.getResidueShading(), null, seq, 3, null));
132   
133  1 newColours[23] = Color.pink;
134  1 av.setGlobalColourScheme(new UserColourScheme(newColours));
135   
136    // gap colour specified as pink
137  1 assertEquals(Color.white, rcf.getResidueColour(false,
138    av.getResidueShading(), null, seq, 3, null));
139    }
140   
141    // TODO more tests for getResidueColour covering groups, feature rendering...
142    }