Clover icon

Coverage Report

  1. Project Clover database Wed Nov 6 2024 14:47:21 GMT
  2. Package jalview.schemes

File ColourSchemePropertyTest.java

 

Code metrics

0
89
2
1
158
119
2
0.02
44.5
2
1

Classes

Class Line # Actions
ColourSchemePropertyTest 36 89 2
1.0100%
 

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.schemes;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertNull;
25    import static org.testng.Assert.assertTrue;
26   
27    import jalview.datamodel.Alignment;
28    import jalview.datamodel.AlignmentI;
29    import jalview.datamodel.Sequence;
30    import jalview.datamodel.SequenceI;
31   
32    import java.awt.Color;
33   
34    import org.testng.annotations.Test;
35   
 
36    public class ColourSchemePropertyTest
37    {
 
38  1 toggle @Test(groups = "Functional")
39    public void testGetColourName()
40    {
41  1 SequenceI seq = new Sequence("Seq1", "abcd");
42  1 AlignmentI al = new Alignment(new SequenceI[] { seq });
43  1 ColourSchemeI cs = new ClustalxColourScheme(al, null);
44  1 assertEquals(ColourSchemeProperty.getColourName(cs), "Clustal");
45  1 cs = new Blosum62ColourScheme();
46  1 assertEquals(ColourSchemeProperty.getColourName(cs), "Blosum62");
47  1 cs = new PIDColourScheme();
48  1 assertEquals(ColourSchemeProperty.getColourName(cs), "% Identity");
49  1 cs = new HydrophobicColourScheme();
50  1 assertEquals(ColourSchemeProperty.getColourName(cs), "Hydrophobic");
51  1 cs = new ZappoColourScheme();
52  1 assertEquals(ColourSchemeProperty.getColourName(cs), "Zappo");
53  1 cs = new TaylorColourScheme();
54  1 assertEquals(ColourSchemeProperty.getColourName(cs), "Taylor");
55  1 cs = new HelixColourScheme();
56  1 assertEquals(ColourSchemeProperty.getColourName(cs),
57    "Helix Propensity");
58  1 cs = new StrandColourScheme();
59  1 assertEquals(ColourSchemeProperty.getColourName(cs),
60    "Strand Propensity");
61  1 cs = new TurnColourScheme();
62  1 assertEquals(ColourSchemeProperty.getColourName(cs), "Turn Propensity");
63  1 cs = new BuriedColourScheme();
64  1 assertEquals(ColourSchemeProperty.getColourName(cs), "Buried Index");
65  1 cs = new NucleotideColourScheme();
66  1 assertEquals(ColourSchemeProperty.getColourName(cs), "Nucleotide");
67  1 cs = new PurinePyrimidineColourScheme();
68  1 assertEquals(ColourSchemeProperty.getColourName(cs),
69    "Purine/Pyrimidine");
70  1 cs = new TCoffeeColourScheme(al);
71  1 assertEquals(ColourSchemeProperty.getColourName(cs), "T-Coffee Scores");
72  1 cs = new RNAHelicesColour(al);
73  1 assertEquals(ColourSchemeProperty.getColourName(cs), "RNA Helices");
74  1 cs = new RNAInteractionColourScheme();
75  1 assertEquals(ColourSchemeProperty.getColourName(cs),
76    "RNA Interaction type");
77  1 cs = new UserColourScheme();
78  1 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
79   
80    /*
81    * UserColourScheme may have a bespoke name
82    */
83  1 ((UserColourScheme) cs).setName("stripy");
84  1 assertEquals(ColourSchemeProperty.getColourName(cs), "stripy");
85  1 ((UserColourScheme) cs).setName("");
86  1 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
87  1 ((UserColourScheme) cs).setName(null);
88  1 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
89   
90  1 assertEquals(ColourSchemeProperty.getColourName(null), "None");
91    }
92   
 
93  1 toggle @Test(groups = "Functional")
94    public void testGetColourScheme()
95    {
96  1 SequenceI seq = new Sequence("Seq1", "abcd");
97  1 AlignmentI al = new Alignment(new SequenceI[] { seq });
98    // the strings here correspond to JalviewColourScheme.toString() values
99  1 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(null, al,
100    "Clustal");
101  1 assertTrue(cs instanceof ClustalxColourScheme);
102    // not case-sensitive
103  1 cs = ColourSchemeProperty.getColourScheme(null, al, "CLUSTAL");
104  1 assertTrue(cs instanceof ClustalxColourScheme);
105  1 cs = ColourSchemeProperty.getColourScheme(null, al, "clustal");
106  1 assertTrue(cs instanceof ClustalxColourScheme);
107  1 cs = ColourSchemeProperty.getColourScheme(null, al, "Blosum62");
108  1 assertTrue(cs instanceof Blosum62ColourScheme);
109  1 cs = ColourSchemeProperty.getColourScheme(null, al, "% Identity");
110  1 assertTrue(cs instanceof PIDColourScheme);
111  1 cs = ColourSchemeProperty.getColourScheme(null, al, "Zappo");
112  1 assertTrue(cs instanceof ZappoColourScheme);
113  1 cs = ColourSchemeProperty.getColourScheme(null, al, "Taylor");
114  1 assertTrue(cs instanceof TaylorColourScheme);
115  1 cs = ColourSchemeProperty.getColourScheme(null, al, "Hydrophobic");
116  1 assertTrue(cs instanceof HydrophobicColourScheme);
117  1 cs = ColourSchemeProperty.getColourScheme(null, al, "Helix Propensity");
118  1 assertTrue(cs instanceof HelixColourScheme);
119  1 cs = ColourSchemeProperty.getColourScheme(null, al,
120    "Strand Propensity");
121  1 assertTrue(cs instanceof StrandColourScheme);
122  1 cs = ColourSchemeProperty.getColourScheme(null, al, "Turn Propensity");
123  1 assertTrue(cs instanceof TurnColourScheme);
124  1 cs = ColourSchemeProperty.getColourScheme(null, al, "Buried Index");
125  1 assertTrue(cs instanceof BuriedColourScheme);
126  1 cs = ColourSchemeProperty.getColourScheme(null, al, "Nucleotide");
127  1 assertTrue(cs instanceof NucleotideColourScheme);
128  1 cs = ColourSchemeProperty.getColourScheme(null, al,
129    "Purine/Pyrimidine");
130  1 assertTrue(cs instanceof PurinePyrimidineColourScheme);
131  1 cs = ColourSchemeProperty.getColourScheme(null, al, "T-Coffee Scores");
132  1 assertTrue(cs instanceof TCoffeeColourScheme);
133  1 cs = ColourSchemeProperty.getColourScheme(null, al, "RNA Helices");
134  1 assertTrue(cs instanceof RNAHelicesColour);
135    // 'None' is a special value
136  1 assertNull(ColourSchemeProperty.getColourScheme(null, al, "None"));
137  1 assertNull(ColourSchemeProperty.getColourScheme(null, al, "none"));
138    // default is to convert the name into a fixed colour
139  1 cs = ColourSchemeProperty.getColourScheme(null, al, "elephants");
140  1 assertTrue(cs instanceof UserColourScheme);
141   
142    /*
143    * explicit aa colours
144    */
145  1 UserColourScheme ucs = (UserColourScheme) ColourSchemeProperty
146    .getColourScheme(null, al,
147    "R,G=red;C=blue;c=green;Q=10,20,30;S,T=11ffdd");
148  1 assertEquals(ucs.findColour('H'), Color.white);
149  1 assertEquals(ucs.findColour('R'), Color.red);
150  1 assertEquals(ucs.findColour('r'), Color.red);
151  1 assertEquals(ucs.findColour('G'), Color.red);
152  1 assertEquals(ucs.findColour('C'), Color.blue);
153  1 assertEquals(ucs.findColour('c'), Color.green);
154  1 assertEquals(ucs.findColour('Q'), new Color(10, 20, 30));
155  1 assertEquals(ucs.findColour('S'), new Color(0x11ffdd));
156  1 assertEquals(ucs.findColour('T'), new Color(0x11ffdd));
157    }
158    }