Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.datamodel.features

File FeatureAttributesTest.java

 

Code metrics

0
45
6
1
158
102
6
0.13
7.5
6
1

Classes

Class Line # Actions
FeatureAttributesTest 40 45 6
1.0100%
 

Contributing tests

This file is covered by 4 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.features;
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.SequenceFeature;
28    import jalview.datamodel.features.FeatureAttributes.Datatype;
29   
30    import java.util.Comparator;
31    import java.util.HashMap;
32    import java.util.Map;
33   
34    import org.testng.annotations.AfterMethod;
35    import org.testng.annotations.BeforeClass;
36    import org.testng.annotations.Test;
37   
38    import junit.extensions.PA;
39   
 
40    public class FeatureAttributesTest
41    {
42   
43    /**
44    * clear down attributes map before tests
45    */
 
46  1 toggle @BeforeClass(alwaysRun = true)
47    public void setUp()
48    {
49  1 FeatureAttributes fa = FeatureAttributes.getInstance();
50  1 ((Map<?, ?>) PA.getValue(fa, "attributes")).clear();
51    }
52   
53    /**
54    * clear down attributes map after tests
55    */
 
56  4 toggle @AfterMethod(alwaysRun = true)
57    public void tearDown()
58    {
59  4 FeatureAttributes fa = FeatureAttributes.getInstance();
60  4 ((Map<?, ?>) PA.getValue(fa, "attributes")).clear();
61    }
62   
63    /**
64    * Test the method that keeps attribute names in non-case-sensitive order,
65    * including handling of 'compound' names
66    */
 
67  1 toggle @Test(groups = "Functional")
68    public void testAttributeNameComparator()
69    {
70  1 FeatureAttributes fa = FeatureAttributes.getInstance();
71  1 Comparator<String[]> comp = (Comparator<String[]>) PA.getValue(fa,
72    "comparator");
73   
74  1 assertEquals(
75    comp.compare(new String[]
76    { "CSQ" }, new String[] { "csq" }), 0);
77   
78  1 assertTrue(
79    comp.compare(new String[]
80    { "CSQ", "a" }, new String[] { "csq" }) > 0);
81   
82  1 assertTrue(
83    comp.compare(new String[]
84    { "CSQ" }, new String[] { "csq", "b" }) < 0);
85   
86  1 assertTrue(
87    comp.compare(new String[]
88    { "CSQ", "AF" }, new String[] { "csq", "ac" }) > 0);
89   
90  1 assertTrue(
91    comp.compare(new String[]
92    { "CSQ", "ac" }, new String[] { "csq", "AF" }) < 0);
93    }
94   
 
95  1 toggle @Test(groups = "Functional")
96    public void testGetMinMax()
97    {
98  1 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
99    "group");
100  1 FeatureAttributes fa = FeatureAttributes.getInstance();
101  1 assertNull(fa.getMinMax("Pfam", "kd"));
102  1 sf.setValue("domain", "xyz");
103  1 assertNull(fa.getMinMax("Pfam", "kd"));
104  1 sf.setValue("kd", "1.3");
105  1 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { 1.3f, 1.3f });
106  1 sf.setValue("kd", "-2.6");
107  1 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { -2.6f, 1.3f });
108    // setting 'mixed' character and numeric values wipes the min/max value
109  1 sf.setValue("kd", "some text");
110  1 assertNull(fa.getMinMax("Pfam", "kd"));
111   
112  1 Map<String, String> csq = new HashMap<>();
113  1 csq.put("AF", "-3");
114  1 sf.setValue("CSQ", csq);
115  1 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
116    new float[]
117    { -3f, -3f });
118  1 csq.put("AF", "4");
119  1 sf.setValue("CSQ", csq);
120  1 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
121    new float[]
122    { -3f, 4f });
123    }
124   
125    /**
126    * Test the method that returns an attribute description, provided it is
127    * recorded and unique
128    */
 
129  1 toggle @Test(groups = "Functional")
130    public void testGetDescription()
131    {
132  1 FeatureAttributes fa = FeatureAttributes.getInstance();
133    // with no description returns null
134  1 assertNull(fa.getDescription("Pfam", "kd"));
135    // with a unique description, returns that value
136  1 fa.addDescription("Pfam", "desc1", "kd");
137  1 assertEquals(fa.getDescription("Pfam", "kd"), "desc1");
138    // with ambiguous description, returns null
139  1 fa.addDescription("Pfam", "desc2", "kd");
140  1 assertNull(fa.getDescription("Pfam", "kd"));
141    }
142   
 
143  1 toggle @Test(groups = "Functional")
144    public void testDatatype()
145    {
146  1 FeatureAttributes fa = FeatureAttributes.getInstance();
147  1 assertNull(fa.getDatatype("Pfam", "kd"));
148  1 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
149    "group");
150  1 sf.setValue("kd", "-1");
151  1 sf.setValue("domain", "Metal");
152  1 sf.setValue("phase", "1");
153  1 sf.setValue("phase", "reverse");
154  1 assertEquals(fa.getDatatype("Pfam", "kd"), Datatype.Number);
155  1 assertEquals(fa.getDatatype("Pfam", "domain"), Datatype.Character);
156  1 assertEquals(fa.getDatatype("Pfam", "phase"), Datatype.Mixed);
157    }
158    }