Clover icon

Coverage Report

  1. Project Clover database Wed Jan 7 2026 02:39:37 GMT
  2. Package jalview.analysis.scoremodels

File ScoreModelsTest.java

 

Code metrics

2
49
4
1
141
82
5
0.1
12.25
4
1.25

Classes

Class Line # Actions
ScoreModelsTest 34 49 5
0.818181881.8%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.analysis.scoremodels;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertTrue;
26   
27    import jalview.api.analysis.PairwiseScoreModelI;
28    import jalview.api.analysis.ScoreModelI;
29   
30    import java.util.Iterator;
31   
32    import org.testng.annotations.Test;
33   
 
34    public class ScoreModelsTest
35    {
36    /**
37    * Verify that the singleton constructor successfully loads Jalview's built-in
38    * score models
39    */
 
40  1 toggle @Test(groups = "Functional")
41    public void testConstructor()
42    {
43  1 Iterator<ScoreModelI> models = ScoreModels.getInstance().getModels()
44    .iterator();
45  1 assertTrue(models.hasNext());
46   
47    /*
48    * models are served in order of addition
49    */
50  1 ScoreModelI sm = models.next();
51  1 assertTrue(sm instanceof SimilarityScoreModel);
52  1 assertTrue(sm instanceof PairwiseScoreModelI);
53  1 assertFalse(sm instanceof DistanceScoreModel);
54  1 assertEquals(sm.getName(), "BLOSUM62");
55  1 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('I', 'R'),
56    -3f);
57   
58  1 sm = models.next();
59  1 assertTrue(sm instanceof SimilarityScoreModel);
60  1 assertTrue(sm instanceof PairwiseScoreModelI);
61  1 assertFalse(sm instanceof DistanceScoreModel);
62  1 assertEquals(sm.getName(), "PAM250");
63  1 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'),
64    -4f);
65   
66  1 sm = models.next();
67  1 assertTrue(sm instanceof SimilarityScoreModel);
68  1 assertTrue(sm instanceof PairwiseScoreModelI);
69  1 assertFalse(sm instanceof DistanceScoreModel);
70  1 assertEquals(sm.getName(), "DNA");
71  1 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('c', 'x'), 1f);
72   
73  1 sm = models.next();
74  1 assertTrue(sm instanceof SimilarityScoreModel);
75  1 assertTrue(sm instanceof PairwiseScoreModelI);
76  1 assertFalse(sm instanceof DistanceScoreModel);
77  1 assertEquals(sm.getName(), "Mat3di");
78  1 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'), -1f);
79  1 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'r'), 6f);
80   
81  1 sm = models.next();
82  1 assertTrue(sm instanceof SimilarityScoreModel);
83  1 assertTrue(sm instanceof PairwiseScoreModelI);
84  1 assertFalse(sm instanceof DistanceScoreModel);
85  1 assertEquals(sm.getName(), "PID");
86  1 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'), 0f);
87  1 assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'r'), 1f);
88   
89  1 sm = models.next();
90  1 assertFalse(sm instanceof SimilarityScoreModel);
91  1 assertFalse(sm instanceof PairwiseScoreModelI);
92  1 assertTrue(sm instanceof DistanceScoreModel);
93  1 assertEquals(sm.getName(), "Sequence Feature Similarity");
94   
95  1 sm = models.next();
96  1 assertFalse(sm instanceof SimilarityScoreModel);
97  1 assertFalse(sm instanceof PairwiseScoreModelI);
98  1 assertTrue(sm instanceof DistanceScoreModel);
99  1 assertEquals(sm.getName(), "Secondary Structure Similarity");
100    }
101   
102    /**
103    * 'Test' that prints out score matrices in tab-delimited format. This test is
104    * intentionally not assigned to any group so would not be run as part of a
105    * suite. It makes no assertions and is just provided as a utility method for
106    * printing out matrices. Relocated here from ScoreMatrixPrinter.
107    */
 
108  0 toggle @Test(groups = "none")
109    public void printAllMatrices_tabDelimited()
110    {
111  0 printAllMatrices(false);
112    }
113   
114    /**
115    * 'Test' that prints out score matrices in html format. This test is
116    * intentionally not assigned to any group so would not be run as part of a
117    * suite. It makes no assertions and is just provided as a utility method for
118    * printing out matrices. Relocated here from ScoreMatrixPrinter.
119    */
 
120  0 toggle @Test(groups = "none")
121    public void printAllMatrices_asHtml()
122    {
123  0 printAllMatrices(true);
124    }
125   
126    /**
127    * Print all registered ScoreMatrix as plain or html tables
128    *
129    * @param asHtml
130    */
 
131  0 toggle protected void printAllMatrices(boolean asHtml)
132    {
133  0 for (ScoreModelI sm : ScoreModels.getInstance().getModels())
134    {
135  0 if (sm instanceof ScoreMatrix)
136    {
137  0 System.out.println(((ScoreMatrix) sm).outputMatrix(asHtml));
138    }
139    }
140    }
141    }