JAL-4090 JAL-1551 source license
[jalview.git] / test / jalview / datamodel / ContactMatrixTest.java
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.datamodel;
22
23 import org.testng.Assert;
24 import org.testng.annotations.BeforeClass;
25 import org.testng.annotations.Test;
26
27 import jalview.gui.JvOptionPane;
28
29 public class ContactMatrixTest
30 {
31   @BeforeClass(alwaysRun = true)
32   public void setUpJvOptionPane()
33   {
34     JvOptionPane.setInteractiveMode(false);
35     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
36   }
37
38   /**
39    * standard asserts for ContactMatrixI
40    */
41   public static void testContactMatrixI(ContactMatrixI cm,
42           boolean symmetric)
43   {
44     // assume contact matrix is square for text
45     ContactListI clist = cm.getContactList(1);
46
47     int width = clist.getContactHeight();
48     Double minValue, maxValue;
49     minValue = clist.getContactAt(0);
50     maxValue = minValue;
51
52     for (int p = 0; p < width; p++)
53     {
54       ContactListI pList = cm.getContactList(p);
55       for (int q = p; q < width; q++)
56       {
57         if (q == p)
58         {
59           // compute minMax for pList
60           minMax(minValue, maxValue, pList);
61
62         }
63         ContactListI qList = cm.getContactList(q);
64         if (symmetric)
65         {
66           Assert.assertEquals(qList.getContactAt(p), pList.getContactAt(q),
67                   "Contact matrix not symmetric");
68         }
69         else
70         {
71           Assert.assertNotEquals(qList.getContactAt(p),
72                   pList.getContactAt(q),
73                   "Contact matrix expected to be not symmetric");
74         }
75       }
76     }
77   }
78
79   private static void minMax(Double minValue, Double maxValue,
80           ContactListI pList)
81   {
82     int width = pList.getContactHeight();
83     for (int rowcol = 0; rowcol < width; rowcol++)
84     {
85       double v = pList.getContactAt(rowcol);
86       if (minValue > v)
87       {
88         minValue = v;
89       }
90       if (maxValue < v)
91       {
92         maxValue = v;
93       }
94     }
95   }
96
97   @Test(groups = { "Functional" })
98   public void testminMaxCalc()
99   {
100     ContactListI clist = new ContactListImpl(new ContactListProviderI()
101     {
102       double[] val = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 };
103
104       @Override
105       public int getPosition()
106       {
107         return 0;
108       }
109
110       @Override
111       public int getContactHeight()
112       {
113         return val.length;
114       }
115
116       @Override
117       public double getContactAt(int column)
118       {
119         if (column < 0 || column >= val.length)
120         {
121           return Double.NaN;
122         }
123         return val[column];
124       }
125
126     });
127     // TODO - write test !
128   }
129
130   /**
131    * test construction and accessors for asymmetric contact matrix
132    */
133   @Test(groups = { "Functional" })
134   public void testAsymmetricContactMatrix()
135   {
136     // TODO - write test !
137
138   }
139
140   /**
141    * test construction and accessors for symmetric contact matrix
142    */
143   @Test(groups = { "Functional" })
144   public void testSymmetricContactMatrix()
145   {
146     // TODO - write test !
147
148   }
149
150 }