1 package jalview.datamodel.features;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNull;
5 import static org.testng.Assert.assertTrue;
7 import jalview.datamodel.SequenceFeature;
8 import jalview.datamodel.features.FeatureAttributes.Datatype;
10 import java.util.Comparator;
11 import java.util.HashMap;
14 import org.testng.annotations.AfterMethod;
15 import org.testng.annotations.BeforeClass;
16 import org.testng.annotations.Test;
18 import junit.extensions.PA;
20 public class FeatureAttributesTest
24 * clear down attributes map before tests
26 @BeforeClass(alwaysRun = true)
29 FeatureAttributes fa = FeatureAttributes.getInstance();
30 ((Map<?, ?>) PA.getValue(fa, "attributes")).clear();
34 * clear down attributes map after tests
36 @AfterMethod(alwaysRun = true)
37 public void tearDown()
39 FeatureAttributes fa = FeatureAttributes.getInstance();
40 ((Map<?, ?>) PA.getValue(fa, "attributes")).clear();
44 * Test the method that keeps attribute names in non-case-sensitive order,
45 * including handling of 'compound' names
47 @Test(groups = "Functional")
48 public void testAttributeNameComparator()
50 FeatureAttributes fa = FeatureAttributes.getInstance();
51 Comparator<String[]> comp = (Comparator<String[]>) PA.getValue(fa,
55 comp.compare(new String[]
56 { "CSQ" }, new String[] { "csq" }), 0);
59 comp.compare(new String[]
60 { "CSQ", "a" }, new String[] { "csq" }) > 0);
63 comp.compare(new String[]
64 { "CSQ" }, new String[] { "csq", "b" }) < 0);
67 comp.compare(new String[]
68 { "CSQ", "AF" }, new String[] { "csq", "ac" }) > 0);
71 comp.compare(new String[]
72 { "CSQ", "ac" }, new String[] { "csq", "AF" }) < 0);
75 @Test(groups = "Functional")
76 public void testGetMinMax()
78 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
80 FeatureAttributes fa = FeatureAttributes.getInstance();
81 assertNull(fa.getMinMax("Pfam", "kd"));
82 sf.setValue("domain", "xyz");
83 assertNull(fa.getMinMax("Pfam", "kd"));
84 sf.setValue("kd", "1.3");
85 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { 1.3f, 1.3f });
86 sf.setValue("kd", "-2.6");
87 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { -2.6f, 1.3f });
88 // setting 'mixed' character and numeric values wipes the min/max value
89 sf.setValue("kd", "some text");
90 assertNull(fa.getMinMax("Pfam", "kd"));
92 Map<String, String> csq = new HashMap<>();
94 sf.setValue("CSQ", csq);
95 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
99 sf.setValue("CSQ", csq);
100 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
106 * Test the method that returns an attribute description, provided it is
107 * recorded and unique
109 @Test(groups = "Functional")
110 public void testGetDescription()
112 FeatureAttributes fa = FeatureAttributes.getInstance();
113 // with no description returns null
114 assertNull(fa.getDescription("Pfam", "kd"));
115 // with a unique description, returns that value
116 fa.addDescription("Pfam", "desc1", "kd");
117 assertEquals(fa.getDescription("Pfam", "kd"), "desc1");
118 // with ambiguous description, returns null
119 fa.addDescription("Pfam", "desc2", "kd");
120 assertNull(fa.getDescription("Pfam", "kd"));
123 @Test(groups = "Functional")
124 public void testDatatype()
126 FeatureAttributes fa = FeatureAttributes.getInstance();
127 assertNull(fa.getDatatype("Pfam", "kd"));
128 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
130 sf.setValue("kd", "-1");
131 sf.setValue("domain", "Metal");
132 sf.setValue("phase", "1");
133 sf.setValue("phase", "reverse");
134 assertEquals(fa.getDatatype("Pfam", "kd"), Datatype.Number);
135 assertEquals(fa.getDatatype("Pfam", "domain"), Datatype.Character);
136 assertEquals(fa.getDatatype("Pfam", "phase"), Datatype.Mixed);