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[] { "CSQ" }, new String[] { "csq" }), 0);
57 assertTrue(comp.compare(new String[] { "CSQ", "a" },
58 new String[] { "csq" }) > 0);
60 assertTrue(comp.compare(new String[] { "CSQ" }, new String[] { "csq",
63 assertTrue(comp.compare(new String[] { "CSQ", "AF" }, new String[] {
66 assertTrue(comp.compare(new String[] { "CSQ", "ac" }, new String[] {
70 @Test(groups = "Functional")
71 public void testGetMinMax()
73 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
75 FeatureAttributes fa = FeatureAttributes.getInstance();
76 assertNull(fa.getMinMax("Pfam", "kd"));
77 sf.setValue("domain", "xyz");
78 assertNull(fa.getMinMax("Pfam", "kd"));
79 sf.setValue("kd", "1.3");
80 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { 1.3f, 1.3f });
81 sf.setValue("kd", "-2.6");
82 assertEquals(fa.getMinMax("Pfam", "kd"), new float[] { -2.6f, 1.3f });
83 // setting 'mixed' character and numeric values wipes the min/max value
84 sf.setValue("kd", "some text");
85 assertNull(fa.getMinMax("Pfam", "kd"));
87 Map<String, String> csq = new HashMap<>();
89 sf.setValue("CSQ", csq);
90 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
94 sf.setValue("CSQ", csq);
95 assertEquals(fa.getMinMax("Pfam", "CSQ", "AF"),
101 * Test the method that returns an attribute description, provided it is
102 * recorded and unique
104 @Test(groups = "Functional")
105 public void testGetDescription()
107 FeatureAttributes fa = FeatureAttributes.getInstance();
108 // with no description returns null
109 assertNull(fa.getDescription("Pfam", "kd"));
110 // with a unique description, returns that value
111 fa.addDescription("Pfam", "desc1", "kd");
112 assertEquals(fa.getDescription("Pfam", "kd"), "desc1");
113 // with ambiguous description, returns null
114 fa.addDescription("Pfam", "desc2", "kd");
115 assertNull(fa.getDescription("Pfam", "kd"));
118 @Test(groups = "Functional")
119 public void testDatatype()
121 FeatureAttributes fa = FeatureAttributes.getInstance();
122 assertNull(fa.getDatatype("Pfam", "kd"));
123 SequenceFeature sf = new SequenceFeature("Pfam", "desc", 10, 20,
125 sf.setValue("kd", "-1");
126 sf.setValue("domain", "Metal");
127 sf.setValue("phase", "1");
128 sf.setValue("phase", "reverse");
129 assertEquals(fa.getDatatype("Pfam", "kd"), Datatype.Number);
130 assertEquals(fa.getDatatype("Pfam", "domain"), Datatype.Character);
131 assertEquals(fa.getDatatype("Pfam", "phase"), Datatype.Mixed);