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