0ae7375ecea6298d3b1bb99aa4a66833162f2ed7
[jalview.git] / test / jalview / schemes / ScoreMatrixTest.java
1 package jalview.schemes;
2
3 import static org.testng.Assert.assertEquals;
4
5 import org.testng.annotations.Test;
6
7 public class ScoreMatrixTest
8 {
9   @Test(groups = "Functional")
10   public void testSymmetric()
11   {
12     verifySymmetric(ResidueProperties.getScoreMatrix("BLOSUM62"));
13     verifySymmetric(ResidueProperties.getScoreMatrix("PAM250"));
14     verifySymmetric(ResidueProperties.getScoreMatrix("DNA"));
15   }
16
17   private void verifySymmetric(ScoreMatrix sm)
18   {
19     int[][] m = sm.getMatrix();
20     int rows = m.length;
21     for (int row = 0; row < rows; row++)
22     {
23       assertEquals(m[row].length, rows);
24       for (int col = 0; col < rows; col++)
25       {
26         // if (m[row][col] != m[col][row])
27         // {
28         // System.out.println(String.format("%s [%d, %d] [%s, %s]",
29         // sm.getName(), m[row][col], m[col][row],
30         // ResidueProperties.aa[row],
31         // ResidueProperties.aa[col]));
32         // }
33         assertEquals(m[row][col], m[col][row], String.format("%s [%s, %s]",
34                 sm.getName(), ResidueProperties.aa[row],
35                 ResidueProperties.aa[col]));
36       }
37     }
38
39     /*
40      * also check the score matrix is sized for 
41      * the number of symbols scored, plus gap
42      */
43     assertEquals(rows, (sm.isDNA() ? ResidueProperties.maxNucleotideIndex
44             : ResidueProperties.maxProteinIndex) + 1);
45   }
46 }