5e44d3ddadf2278bb83f85f4c1a0c8bff76f773e
[jalview.git] / test / jalview / analysis / scoremodels / ScoreModelsTest.java
1 package jalview.analysis.scoremodels;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
6
7 import jalview.api.analysis.PairwiseScoreModelI;
8 import jalview.api.analysis.ScoreModelI;
9
10 import java.util.Iterator;
11
12 import org.testng.annotations.Test;
13
14 public class ScoreModelsTest
15 {
16   /**
17    * Verify that the singleton constructor successfully loads Jalview's built-in
18    * score models
19    */
20   @Test(groups = "Functional")
21   public void testConstructor()
22   {
23     Iterator<ScoreModelI> models = ScoreModels.getInstance().getModels()
24             .iterator();
25     assertTrue(models.hasNext());
26
27     /*
28      * models are served in order of addition
29      */
30     ScoreModelI sm = models.next();
31     assertTrue(sm instanceof SimilarityScoreModel);
32     assertTrue(sm instanceof PairwiseScoreModelI);
33     assertFalse(sm instanceof DistanceScoreModel);
34     assertEquals(sm.getName(), "BLOSUM62");
35     assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('I', 'R'), -3f);
36
37     sm = models.next();
38     assertTrue(sm instanceof SimilarityScoreModel);
39     assertTrue(sm instanceof PairwiseScoreModelI);
40     assertFalse(sm instanceof DistanceScoreModel);
41     assertEquals(sm.getName(), "PAM250");
42     assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'), -4f);
43
44     sm = models.next();
45     assertTrue(sm instanceof SimilarityScoreModel);
46     assertTrue(sm instanceof PairwiseScoreModelI);
47     assertFalse(sm instanceof DistanceScoreModel);
48     assertEquals(sm.getName(), "DNA");
49     assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('c', 'x'), 1f);
50
51     sm = models.next();
52     assertTrue(sm instanceof SimilarityScoreModel);
53     assertTrue(sm instanceof PairwiseScoreModelI);
54     assertFalse(sm instanceof DistanceScoreModel);
55     assertEquals(sm.getName(), "PID");
56     assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'), 0f);
57     assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'r'), 1f);
58
59     sm = models.next();
60     assertFalse(sm instanceof SimilarityScoreModel);
61     assertFalse(sm instanceof PairwiseScoreModelI);
62     assertTrue(sm instanceof DistanceScoreModel);
63     assertEquals(sm.getName(), "Sequence Feature Similarity");
64   }
65
66   /**
67    * 'Test' that prints out score matrices in tab-delimited format. This test is
68    * intentionally not assigned to any group so would not be run as part of a
69    * suite. It makes no assertions and is just provided as a utility method for
70    * printing out matrices. Relocated here from ScoreMatrixPrinter.
71    */
72   @Test(groups = "none")
73   public void printAllMatrices_tabDelimited()
74   {
75     printAllMatrices(false);
76   }
77
78   /**
79    * 'Test' that prints out score matrices in html format. This test is
80    * intentionally not assigned to any group so would not be run as part of a
81    * suite. It makes no assertions and is just provided as a utility method for
82    * printing out matrices. Relocated here from ScoreMatrixPrinter.
83    */
84   @Test(groups = "none")
85   public void printAllMatrices_asHtml()
86   {
87     printAllMatrices(true);
88   }
89
90   /**
91    * Print all registered ScoreMatrix as plain or html tables
92    * 
93    * @param asHtml
94    */
95   protected void printAllMatrices(boolean asHtml)
96   {
97     for (ScoreModelI sm : ScoreModels.getInstance().getModels())
98     {
99       if (sm instanceof ScoreMatrix)
100       {
101         System.out.println(((ScoreMatrix) sm).outputMatrix(asHtml));
102       }
103     }
104   }
105 }