From 84233f5cfbe9907cbd390db92db8e267de1a02e3 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 23 Jan 2017 14:42:18 +0000 Subject: [PATCH] JAL-2349 test for ContactMatrixI/ContactListI/ContactListProviderI chain --- test/jalview/datamodel/ContactMatrixTest.java | 120 +++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 test/jalview/datamodel/ContactMatrixTest.java diff --git a/test/jalview/datamodel/ContactMatrixTest.java b/test/jalview/datamodel/ContactMatrixTest.java new file mode 100644 index 0000000..f0861e9 --- /dev/null +++ b/test/jalview/datamodel/ContactMatrixTest.java @@ -0,0 +1,120 @@ +package jalview.datamodel; + +import jalview.gui.JvOptionPane; + +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class ContactMatrixTest +{ + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + /** + * standard asserts for ContactMatrixI + */ + public static void testContactMatrixI(ContactMatrixI cm, boolean symmetric) + { + // assume contact matrix is square for text + ContactListI clist = cm.getContactList(1); + + int width = clist.getContactHeight(); + Double minValue, maxValue; + minValue = clist.getContactAt(0); + maxValue = minValue; + + for (int p = 0; p < width; p++) + { + ContactListI pList = cm.getContactList(p); + for (int q = p; q < width; q++) + { + if (q == p) + { + // compute minMax for pList + minMax(minValue, maxValue, pList); + + } + ContactListI qList = cm.getContactList(q); + if (symmetric) + { + Assert.assertEquals(qList.getContactAt(p), pList.getContactAt(q), + "Contact matrix not symmetric"); + } + else + { + Assert.assertNotEquals(qList.getContactAt(p), + pList.getContactAt(q), + "Contact matrix expected to be not symmetric"); + } + } + } + } + + private static void minMax(Double minValue, Double maxValue, + ContactListI pList) + { + int width = pList.getContactHeight(); + for (int rowcol = 0; rowcol < width; rowcol++) + { + double v = pList.getContactAt(rowcol); + if (minValue > v) + { + minValue = v; + } + if (maxValue < v) + { + maxValue = v; + } + } + } + + @Test(groups = { "Functional" }) + public void testminMaxCalc() + { + ContactListI clist = new ContactListImpl(new ContactListProviderI() + { + double[] val = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 }; + + @Override + public int getContactHeight() + { + return val.length; + } + + @Override + public double getContactAt(int column) + { + if (column < 0 || column >= val.length) + { + return Double.NaN; + } + return val[column]; + } + + }); + } + + /** + * test construction and accessors for asymmetric contact matrix + */ + @Test(groups = { "Functional" }) + public void testAsymmetricContactMatrix() + { + + } + + /** + * test construction and accessors for symmetric contact matrix + */ + @Test(groups = { "Functional" }) + public void testSymmetricContactMatrix() + { + + } + +} -- 1.7.10.2