1 package jalview.analysis.scoremodels;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
7 import jalview.api.analysis.PairwiseScoreModelI;
8 import jalview.api.analysis.ScoreModelI;
10 import java.lang.reflect.Constructor;
11 import java.lang.reflect.InvocationTargetException;
12 import java.util.Iterator;
14 import org.testng.annotations.Test;
16 public class ScoreModelsTest
19 * Verify that the singleton constructor successfully loads Jalview's built-in
22 @Test(groups = "Functional")
23 public void testConstructor()
25 Iterator<ScoreModelI> models = ScoreModels.getInstance().getModels()
27 assertTrue(models.hasNext());
30 * models are served in order of addition
32 ScoreModelI sm = models.next();
33 assertTrue(sm instanceof SimilarityScoreModel);
34 assertTrue(sm instanceof PairwiseScoreModelI);
35 assertFalse(sm instanceof DistanceScoreModel);
36 assertEquals(sm.getName(), "BLOSUM62");
37 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('I', 'R'), -3f);
40 assertTrue(sm instanceof SimilarityScoreModel);
41 assertTrue(sm instanceof PairwiseScoreModelI);
42 assertFalse(sm instanceof DistanceScoreModel);
43 assertEquals(sm.getName(), "PAM250");
44 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'), -4f);
47 assertTrue(sm instanceof SimilarityScoreModel);
48 assertTrue(sm instanceof PairwiseScoreModelI);
49 assertFalse(sm instanceof DistanceScoreModel);
50 assertEquals(sm.getName(), "DNA");
51 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('c', 'x'), 1f);
54 assertTrue(sm instanceof SimilarityScoreModel);
55 assertTrue(sm instanceof PairwiseScoreModelI);
56 assertFalse(sm instanceof DistanceScoreModel);
57 assertEquals(sm.getName(), "PID");
58 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'), 0f);
59 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'r'), 1f);
62 assertFalse(sm instanceof SimilarityScoreModel);
63 assertFalse(sm instanceof PairwiseScoreModelI);
64 assertTrue(sm instanceof DistanceScoreModel);
65 assertEquals(sm.getName(), "Sequence Feature Similarity");
69 * 'Test' that prints out score matrices in tab-delimited format. This test is
70 * intentionally not assigned to any group so would not be run as part of a
71 * suite. It makes no assertions and is just provided as a utility method for
72 * printing out matrices. Relocated here from ScoreMatrixPrinter.
74 @Test(groups = "none")
75 public void printAllMatrices_tabDelimited()
77 printAllMatrices(false);
81 * 'Test' that prints out score matrices in html format. This test is
82 * intentionally not assigned to any group so would not be run as part of a
83 * suite. It makes no assertions and is just provided as a utility method for
84 * printing out matrices. Relocated here from ScoreMatrixPrinter.
86 @Test(groups = "none")
87 public void printAllMatrices_asHtml()
89 printAllMatrices(true);
93 * Print all registered ScoreMatrix as plain or html tables
97 protected void printAllMatrices(boolean asHtml)
99 for (ScoreModelI sm : ScoreModels.getInstance().getModels())
101 if (sm instanceof ScoreMatrix)
103 System.out.println(((ScoreMatrix) sm).outputMatrix(asHtml));
108 @Test(groups = "Functional")
109 public void testInstantiate()
110 throws InstantiationException, IllegalAccessException,
111 NoSuchMethodException, SecurityException,
112 IllegalArgumentException, InvocationTargetException
114 Class<? extends Object> c = ScoreModels.class;
115 Constructor<? extends Object> con = c.getDeclaredConstructor();
116 con.setAccessible(true);
117 Object o = con.newInstance();
118 System.out.println(o);