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.Test;
17 import junit.extensions.PA;
19 public class FeatureAttributesTest
23 * clear down attributes map after tests
26 public void tearDown()
28 FeatureAttributes fa = FeatureAttributes.getInstance();
29 ((Map<?, ?>) PA.getValue(fa, "attributes")).clear();
33 * Test the method that keeps attribute names in non-case-sensitive order,
34 * including handling of 'compound' names
36 @Test(groups="Functional")
37 public void testAttributeNameComparator()
39 FeatureAttributes fa = FeatureAttributes.getInstance();
40 Comparator<String[]> comp = (Comparator<String[]>) PA.getValue(fa,
44 comp.compare(new String[] { "CSQ" }, new String[] { "csq" }), 0);
46 assertTrue(comp.compare(new String[] { "CSQ", "a" },
47 new String[] { "csq" }) > 0);
49 assertTrue(comp.compare(new String[] { "CSQ" }, new String[] { "csq",
52 assertTrue(comp.compare(new String[] { "CSQ", "AF" }, new String[] {
55 assertTrue(comp.compare(new String[] { "CSQ", "ac" }, new String[] {
60 public void testGetMinMax()
62 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
64 FeatureAttributes fa = FeatureAttributes.getInstance();
65 assertNull(fa.getMinMax("Pfam", "kd"));
66 sf.setValue("domain", "xyz");
67 assertNull(fa.getMinMax("Pfam", "kd"));
68 sf.setValue("kd", "some text");
69 assertNull(fa.getMinMax("Pfam", "kd"));
70 sf.setValue("kd", "1.3");
71 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { 1.3f, 1.3f });
72 sf.setValue("kd", "-2.6");
73 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { -2.6f, 1.3f });
74 Map<String, String> csq = new HashMap<>();
76 sf.setValue("CSQ", csq);
77 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
81 sf.setValue("CSQ", csq);
82 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
88 * Test the method that returns an attribute description, provided it is
92 public void testGetDescription()
94 FeatureAttributes fa = FeatureAttributes.getInstance();
95 // with no description returns null
96 assertNull(fa.getDescription("Pfam", "kd"));
97 // with a unique description, returns that value
98 fa.addDescription("Pfam", "desc1", "kd");
99 assertEquals(fa.getDescription("Pfam", "kd"), "desc1");
100 // with ambiguous description, returns null
101 fa.addDescription("Pfam", "desc2", "kd");
102 assertNull(fa.getDescription("Pfam", "kd"));
106 public void testDatatype()
108 FeatureAttributes fa = FeatureAttributes.getInstance();
109 assertNull(fa.getDatatype("Pfam", "kd"));
110 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
112 sf.setValue("kd", "-1");
113 sf.setValue("domain", "Metal");
114 sf.setValue("phase", "1");
115 sf.setValue("phase", "reverse");
116 assertEquals(fa.getDatatype("Pfam", "kd"), Datatype.Number);
117 assertEquals(fa.getDatatype("Pfam", "domain"), Datatype.Character);
118 assertEquals(fa.getDatatype("Pfam", "phase"), Datatype.Mixed);