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