From eda5288df7e4abec5e52cc5e74a5d32aadfe08b5 Mon Sep 17 00:00:00 2001 From: "Pedro T. Monteiro" Date: Sat, 14 Jul 2018 15:45:33 +0100 Subject: [PATCH] JUnit test separation. Updated EpiLog version v1.1 --- src/main/java/org/epilogtool/io/FileIO.java | 55 ++- .../{TestHelper.java => FileUtils.java} | 4 +- .../org/epilogtool/core/AllCoreTests.java | 4 +- .../epilogtool/core/EpitheliumCellTest.java | 352 +----------------- .../org/epilogtool/core/EpitheliumTest.java | 85 +++++ .../epilogtool/core/InitialConditionTest.java | 40 ++ .../core/IntegrationFunctionsTest.java | 76 ++++ .../org/epilogtool/core/LoadProjectTest.java | 75 ++++ .../org/epilogtool/core/ModelUpdateTest.java | 47 +++ .../org/epilogtool/core/NeighboursTest.java | 131 +++++++ .../org/epilogtool/core/PerturbationTest.java | 48 +++ .../org/epilogtool/core/SimulationTest.java | 30 ++ 12 files changed, 578 insertions(+), 369 deletions(-) rename src/test/java/org/epilogtool/{TestHelper.java => FileUtils.java} (85%) create mode 100644 src/test/java/org/epilogtool/core/EpitheliumTest.java create mode 100644 src/test/java/org/epilogtool/core/InitialConditionTest.java create mode 100644 src/test/java/org/epilogtool/core/IntegrationFunctionsTest.java create mode 100644 src/test/java/org/epilogtool/core/LoadProjectTest.java create mode 100644 src/test/java/org/epilogtool/core/ModelUpdateTest.java create mode 100644 src/test/java/org/epilogtool/core/NeighboursTest.java create mode 100644 src/test/java/org/epilogtool/core/PerturbationTest.java create mode 100644 src/test/java/org/epilogtool/core/SimulationTest.java diff --git a/src/main/java/org/epilogtool/io/FileIO.java b/src/main/java/org/epilogtool/io/FileIO.java index 4f405cb..c8abd1f 100644 --- a/src/main/java/org/epilogtool/io/FileIO.java +++ b/src/main/java/org/epilogtool/io/FileIO.java @@ -111,46 +111,41 @@ public static File copyFile(File srcFile, String destDir) { return fDestDir; } - private static void unZipIt(String zipFile, File folder) { + private static void unZipIt(String zipFile, File folder) throws IOException { byte[] buffer = new byte[1024]; - try { - if (!folder.exists()) { - folder.mkdir(); - } + if (!folder.exists()) { + folder.mkdir(); + } - // get the zip file content - ZipInputStream zis = new ZipInputStream(new FileInputStream(new File(zipFile))); - // get the zipped file list entry - ZipEntry ze = zis.getNextEntry(); + // get the zip file content + ZipInputStream zis = new ZipInputStream(new FileInputStream(new File(zipFile))); + // get the zipped file list entry + ZipEntry ze = zis.getNextEntry(); - while (ze != null) { + while (ze != null) { - String fileName = ze.getName().split("/")[ze.getName().split("/").length - 1]; - File newFile = new File(folder + File.separator + fileName); + String fileName = ze.getName().split("/")[ze.getName().split("/").length - 1]; + File newFile = new File(folder + File.separator + fileName); - // create all non exists folders - // else you will hit FileNotFoundException for compressed folder - new File(newFile.getParent()).mkdirs(); + // create all non exists folders + // else you will hit FileNotFoundException for compressed folder + new File(newFile.getParent()).mkdirs(); - FileOutputStream fos = new FileOutputStream(newFile); + FileOutputStream fos = new FileOutputStream(newFile); - int len; - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } - - fos.close(); - ze = zis.getNextEntry(); + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); } - zis.closeEntry(); - zis.close(); - - } catch (IOException ex) { - ex.printStackTrace(); + fos.close(); + ze = zis.getNextEntry(); } + + zis.closeEntry(); + zis.close(); } public static LogicalModel loadSBMLModel(File file) throws IOException { @@ -176,9 +171,7 @@ public static LogicalModel loadSBMLModel(File file) throws IOException { * @throws SecurityException * @throws ClassNotFoundException */ - public static boolean loadPEPS(String filename) - throws IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, - InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { + public static boolean loadPEPS(String filename) throws IOException { File tmpFolder = FileIO.unzipPEPSTmpDir(filename); boolean load = false; // Loads all the epithelium from the config.txt configuration file diff --git a/src/test/java/org/epilogtool/TestHelper.java b/src/test/java/org/epilogtool/FileUtils.java similarity index 85% rename from src/test/java/org/epilogtool/TestHelper.java rename to src/test/java/org/epilogtool/FileUtils.java index 02f892a..ba63048 100644 --- a/src/test/java/org/epilogtool/TestHelper.java +++ b/src/test/java/org/epilogtool/FileUtils.java @@ -2,7 +2,7 @@ import java.io.File; -public class TestHelper { +public class FileUtils { static File resourceFolder; static { resourceFolder = new File("target", "test-classes"); @@ -11,7 +11,7 @@ public class TestHelper { } } - public static File getTestResource(String group, String name) { + public static File getResource(String group, String name) { File dir = resourceFolder; if (group != null && group.length() > 0) { diff --git a/src/test/java/org/epilogtool/core/AllCoreTests.java b/src/test/java/org/epilogtool/core/AllCoreTests.java index 29814a8..786c82e 100644 --- a/src/test/java/org/epilogtool/core/AllCoreTests.java +++ b/src/test/java/org/epilogtool/core/AllCoreTests.java @@ -5,7 +5,9 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses( { EpitheliumCellTest.class }) +@SuiteClasses({ LoadProjectTest.class, EpitheliumTest.class, IntegrationFunctionsTest.class, + ModelUpdateTest.class, NeighboursTest.class, InitialConditionTest.class, + PerturbationTest.class, EpitheliumCellTest.class, SimulationTest.class }) public class AllCoreTests { } diff --git a/src/test/java/org/epilogtool/core/EpitheliumCellTest.java b/src/test/java/org/epilogtool/core/EpitheliumCellTest.java index c3e8d1e..b8143fc 100644 --- a/src/test/java/org/epilogtool/core/EpitheliumCellTest.java +++ b/src/test/java/org/epilogtool/core/EpitheliumCellTest.java @@ -1,385 +1,67 @@ package org.epilogtool.core; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; import org.colomoto.biolqm.LogicalModel; -import org.colomoto.biolqm.NodeInfo; -import org.colomoto.biolqm.modifier.perturbation.AbstractPerturbation; -import org.colomoto.biolqm.modifier.perturbation.RangePerturbation; -import org.epilogtool.TestHelper; -import org.epilogtool.common.EnumRandomSeed; -import org.epilogtool.common.Tuple2D; -import org.epilogtool.common.Txt; +import org.epilogtool.FileUtils; import org.epilogtool.io.FileIO; -import org.epilogtool.notification.NotificationManager; import org.epilogtool.project.Project; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; public class EpitheliumCellTest { private final static String YellowRedName = "YellowRed.sbml"; private final static String GreenRedName = "GreenRed.sbml"; - private final static String GreenBlueName = "GreenBlue.sbml"; - private final static String filePepsName = "ColorModels.peps"; - private final static String noConfigPepsName = "NoConfig.peps"; - private final static String noSBMLPepsName = "NoSBML.peps"; - - private static EpitheliumCell epicell; - private static LogicalModel YellowRed; - private static LogicalModel GreenRed; - private Map, Map>>> relativeNeighboursCache = new HashMap, Map>>>(); - - // Test if an sbml is properly loaded @BeforeClass public static void loadModelBeforeTests() throws IOException { - - File fYellowRed = TestHelper.getTestResource("testModels", YellowRedName); - File fGreenRed = TestHelper.getTestResource("testModels", GreenRedName); - - YellowRed = FileIO.loadSBMLModel(fYellowRed); - GreenRed = FileIO.loadSBMLModel(fGreenRed); - - } - - @Before - public void loadEpiCellBeforeEachTest() { - epicell = new EpitheliumCell(YellowRed); - } - - // Test if a project (Peps file) is properly loaded - @Test - public void loadProjectTest() throws IOException { - - File filePeps = TestHelper.getTestResource("testProjects", filePepsName); - File noConfigPepsFile = TestHelper.getTestResource("testProjects", noConfigPepsName); - File noSBMLPepsFile = TestHelper.getTestResource("testProjects", noSBMLPepsName); - - NotificationManager.setGUI(false); - try { - assertFalse(FileIO.loadPEPS(noConfigPepsFile.getAbsolutePath())); - } catch (Exception e) { - fail(""); - } - - try { - assertTrue(FileIO.loadPEPS(filePeps.getAbsolutePath())); - } catch (Exception e) { - fail(""); - } - NotificationManager.setGUI(true); - } - - // Tests if rollOver is being identified - // ColorModels EP0 = Torus - // ColorModels EP1 = Rectangular - @Test - public void Ep0Test() throws IOException { - - // RollOver - assertEquals(Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getTopology().getRollOver() - .toString(), Txt.get("s_Rollover_B")); - - // Topology - assertEquals( - Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getTopology().getDescription(), - "Pointy-Odd"); - - // EpitheliumName - assertEquals(Project.getInstance().getEpitheliumList().get(0).getName(), "Epi_0"); - - // Dimensions - assertEquals(Project.getInstance().getEpitheliumList().get(0).getX(), 10); - assertEquals(Project.getInstance().getEpitheliumList().get(0).getY(), 10); - - // Models on Epithelium -> how many models on - List setLogicalModel = new ArrayList(); - setLogicalModel.add(YellowRed); - setLogicalModel.add(GreenRed); - - List setLogicalModelFile = new ArrayList(); - for (LogicalModel m : Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getModelSet()) { - Project.getInstance().getProjectFeatures().getModelName(m); - if (Project.getInstance().getProjectFeatures().getModelName(m).equals(YellowRedName) - | Project.getInstance().getProjectFeatures().getModelName(m).equals(GreenRedName)) { - setLogicalModelFile.add(m); - } - } - assertEquals(setLogicalModelFile.size(), setLogicalModel.size()); - - // InputDefinitions -> integration functions - - } - - @Test - public void integrationFunctions() { - - Set integrationInputs = new HashSet(); - - integrationInputs.add(YellowRed.getComponent("Yellow")); - integrationInputs.add(GreenRed.getComponent("Green")); - - String strIntFunctions = "[Yellow, Green]"; - String strIntFunctions_2 = "[Green, Yellow]"; - boolean bFlag = true; - - // Test if the integration inputs are correct - if ((Project.getInstance().getEpitheliumList().get(0).getIntegrationNodes().toString().equals(strIntFunctions) || - (Project.getInstance().getEpitheliumList().get(0).getIntegrationNodes().toString().equals(strIntFunctions_2)))){ - assertTrue(bFlag); - } - - // Test if the integration functions are correct - Set strIntegrationFunctions_ctr = new HashSet(); - strIntegrationFunctions_ctr.add("{Red [1]}"); - strIntegrationFunctions_ctr.add("{Red [0:20]}"); - - Set strIntegrationFunctions = new HashSet(); - for (NodeInfo nodeInt : integrationInputs) { - // System.out.println(nodeInt); - - NodeInfo node = Project.getInstance().getEpitheliumList().get(0).getComponentUsed(nodeInt.getNodeID()); - - ComponentIntegrationFunctions cif = Project.getInstance().getEpitheliumList().get(0) - .getIntegrationFunctions().getAllIntegrationFunctions().get(node); - // System.out.println(Project.getInstance().getEpitheliumList().get(0).getIntegrationFunctions().getAllIntegrationFunctions().get(node)); - for (String strIntFunction : cif.getFunctions()) { - strIntegrationFunctions.add(strIntFunction); - } - } - assertEquals(strIntegrationFunctions, strIntegrationFunctions_ctr); - } - - @Test - public void initialConditions() { - // Tests 1) if the initial condition is properly read; 2) if the percentage is - // properly measured - - byte b; - - b = Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getCellValue(0, 0, "Red"); - assertEquals(b, (byte) 0); - - b = Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getCellValue(9, 9, "Red"); - assertEquals(b, (byte) 1); - - String strPercentage = Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid() - .getPercentage("Red"); - assertEquals(strPercentage, "(1 : 59%)"); - } - - @Test - public void perturbations() { - // Tests 1) if the perturbations are properly defined - - assertEquals(Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getPerturbation(4, 5) - .getStringRepresentation(), "Red%0"); - assertEquals(Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getPerturbation(5, 4) - .getStringRepresentation(), "Red%1"); - assertEquals(Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getPerturbation(0, 0), null); - - // TODO: get a model with more than one value to check the range - } - - @Test - public void cellularModelUpdate() { - LogicalModel m = Project.getInstance().getProjectFeatures().getModel(YellowRedName); - assertEquals(Project.getInstance().getEpitheliumList().get(0).getPriorityClasses(m).getClassVars(0).toString(), - "[Yellow, Red]"); - - // TODO: get a model with more than one component - } - - @Test - public void epitheliumModelUpdate() { - - EnumRandomSeed rsType = Project.getInstance().getEpitheliumList().get(0).getUpdateSchemeInter() - .getRandomSeedType(); - - // alpha - assertEquals(Project.getInstance().getEpitheliumList().get(0).getUpdateSchemeInter().getAlpha(), (float) 0, 96); - - // Random seed - // assertThat(Project.getInstance().getEpitheliumList().get(0).getUpdateSchemeInter().getRandomSeed(),not(rsType.equals(EnumRandomSeed.FIXED))); - - // Updated cells - assertEquals(Project.getInstance().getEpitheliumList().get(0).getUpdateSchemeInter().getUpdateCells(), - (UpdateCells.fromString("Only updatable cells"))); - } - - @Test - public void simulation() { - - // TODO - // verify nextStep - Random Seed. everythont is diferentt - // verify terminal cyle - // verify stable pattern - // verify perturb model - - } - - public void neighbours(int index, List neighboursNumber, int x, int y, int max) { - - // int minSign = 1; - for (int maxSign = 0; maxSign < max; maxSign++) { - - // verify cumulative distances - int minSign = 1; - Tuple2D rangePair = new Tuple2D(minSign, maxSign); - Tuple2D rangeList_aux = new Tuple2D(0, (minSign - 1 > 0) ? minSign - 1 : 0); - - Set> posNeighbours = Project.getInstance().getEpitheliumList().get(index) - .getEpitheliumGrid() - .getPositionNeighbours(this.relativeNeighboursCache, rangeList_aux, rangePair, minSign, x, y); - - int number = 0; - for (int ind = 0; ind <= maxSign; ind++) { - number = number + neighboursNumber.get(ind); - } - - assertEquals(posNeighbours.size(), number); - - // verify exact distances - // must increase the value of minSig to have exactly the same number of - // neighbours - - minSign = maxSign; - rangePair = new Tuple2D(minSign, maxSign); - rangeList_aux = new Tuple2D(0, (minSign - 1 > 0) ? minSign - 1 : 0); - posNeighbours = Project.getInstance().getEpitheliumList().get(index).getEpitheliumGrid() - .getPositionNeighbours(this.relativeNeighboursCache, rangeList_aux, rangePair, minSign, x, y); - - // System.out.println(posNeighbours); - number = neighboursNumber.get(maxSign); - if (minSign == 0) - number = 1; - assertEquals(posNeighbours.size(), number); - } - - } - - public void neighbourRange(int index, int minSign, int maxSign, int x, int y, int expectedNumber) { - - Tuple2D rangePair = new Tuple2D(minSign, maxSign); - Tuple2D rangeList_aux = new Tuple2D(0, (minSign - 1 > 0) ? minSign - 1 : 0); - - Set> posNeighbours = Project.getInstance().getEpitheliumList().get(index) - .getEpitheliumGrid() - .getPositionNeighbours(this.relativeNeighboursCache, rangeList_aux, rangePair, minSign, x, y); - - assertEquals(posNeighbours.size(), expectedNumber); - - } - - public boolean neighbourPresent(int index, int minSign, int maxSign, int x, int y, int Nx, int Ny) { - Tuple2D rangePair = new Tuple2D(minSign, maxSign); - Tuple2D rangeList_aux = new Tuple2D(0, (minSign - 1 > 0) ? minSign - 1 : 0); - - Set> posNeighbours = Project.getInstance().getEpitheliumList().get(index) - .getEpitheliumGrid() - .getPositionNeighbours(this.relativeNeighboursCache, rangeList_aux, rangePair, minSign, x, y); - - return posNeighbours.contains(new Tuple2D(Nx, Ny)); - } - - - @Test - public void neighbours() { - - // ***************PointyOdd - neighbours(0, Arrays.asList(0, 6, 12, 18, 24, 23, 12, 4), 0, 0, 8); // Torus - neighbourRange(0, 0,-1, 0, 0,100); // Torus range[0:] - neighbourRange(0, 1,-1, 0, 0,99); // Torus range[1:] - neighbourRange(0, 1,40, 0, 0,99); // Torus range[1:40] - - - neighbours(1, Arrays.asList(0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 9, 7, 5, 3, 1), 0, 0, 14); // rectangular - neighbours(2, Arrays.asList(0, 4, 7, 10, 13, 15, 14, 13, 12, 11), 0, 0, 9); // Horizontal - neighbours(3, Arrays.asList(0, 3, 7, 9, 13, 12, 10, 10, 10, 10, 9, 5, 1), 0, 0, 10); // vertical - - // ***************PointyEven - neighbours(4, Arrays.asList(0, 6, 12, 18, 24, 23, 12, 4), 0, 0, 8); // Torus - neighbours(5, Arrays.asList(0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 9, 7, 5, 3, 1), 0, 0, 14); // rectangular - neighbours(6, Arrays.asList(0, 4, 7, 10, 13, 15, 14, 13, 12, 11), 0, 0, 9); // Horizontal - neighbours(7, Arrays.asList(0, 3, 7, 9, 13, 12, 10, 10, 10, 10, 9, 5, 1), 0, 0, 10); // vertical - - // ***************FlatOdd - neighbours(8, Arrays.asList(0, 6, 12, 18, 24, 23, 12, 4), 0, 0, 8); // Torus - neighbours(9, Arrays.asList(0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 9, 7, 5, 3, 1), 0, 0, 14); // rectangular - neighbours(10, Arrays.asList(0, 4, 7, 10, 13, 15, 14, 13, 12, 11), 0, 0, 9); // Horizontal - neighbours(11, Arrays.asList(0, 3, 7, 9, 13, 12, 10, 10, 10, 10, 9, 5, 1), 0, 0, 10); // vertical - - // ***************FlatEven - neighbours(12, Arrays.asList(0, 6, 12, 18, 24, 23, 12, 4), 0, 0, 8); // Torus - neighbours(13, Arrays.asList(0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 9, 7, 5, 3, 1), 0, 0, 14); // rectangular - neighbours(14, Arrays.asList(0, 4, 7, 10, 13, 15, 14, 13, 12, 11), 0, 0, 9); // Horizontal - neighbours(15, Arrays.asList(0, 3, 7, 9, 13, 12, 10, 10, 10, 10, 9, 5, 1), 0, 0, 10); // vertical - - // TODO: verify neighbours for intermediate values - assertFalse(neighbourPresent(0, 2, 4, 0, 0,0,0)); - assertTrue(neighbourPresent(0, 2, 4, 0, 0,0,2)); - + File filePeps = FileUtils.getResource("testProjects", filePepsName); + FileIO.loadPEPS(filePeps.getAbsolutePath()); } @Test public void cellularModelOnCell() { - - LogicalModel m = Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getModel(0, 0); + Epithelium epi = Project.getInstance().getEpitheliumList().get(0); + LogicalModel m = epi.getModel(0, 0); assertEquals(Project.getInstance().getProjectFeatures().getModelName(m), YellowRedName); - m = Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getModel(6, 0); + m = epi.getModel(6, 0); assertEquals(Project.getInstance().getProjectFeatures().getModelName(m), GreenRedName); } @Test public void cleanSlateTest() { + Epithelium epi = Project.getInstance().getEpitheliumList().get(0); + LogicalModel m = epi.getModel(0, 0); + EpitheliumCell epicell = new EpitheliumCell(m); + assertNull(epicell.getPerturbation()); byte[] state = epicell.getState(); assertNotNull(state); - for (int i = 0; i < YellowRed.getComponents().size(); i++) { + for (int i = 0; i < m.getComponents().size(); i++) { assertEquals(0, state[i]); } assertNotNull(epicell.getModel()); - assertEquals(YellowRed, epicell.getModel()); - } - - @Test - public void perturbationTest() { - AbstractPerturbation rp = new RangePerturbation(YellowRed.getComponents().get(0), 0, 1); - epicell.setPerturbation(rp); - assertEquals(rp, epicell.getPerturbation()); + assertEquals(m, epicell.getModel()); } - // @Test - // public void hasNodeTest() { - // assertEquals(epicell.getNodeIndex("Green"), 0); - //// assertEquals(epicell.getNodeIndex("Y"), -1); - // } - @Test public void cloneTest() { + Epithelium epi = Project.getInstance().getEpitheliumList().get(0); + LogicalModel m = epi.getModel(0, 0); + EpitheliumCell epicell = new EpitheliumCell(m); + EpitheliumCell clone = epicell.clone(); assertEquals(clone.getModel(), epicell.getModel()); assertEquals(clone.getPerturbation(), epicell.getPerturbation()); assertNotNull(clone.getState()); - for (int i = 0; i < YellowRed.getComponents().size(); i++) { + for (int i = 0; i < m.getComponents().size(); i++) { assertEquals(clone.getState()[i], epicell.getState()[i]); } } diff --git a/src/test/java/org/epilogtool/core/EpitheliumTest.java b/src/test/java/org/epilogtool/core/EpitheliumTest.java new file mode 100644 index 0000000..c28fe91 --- /dev/null +++ b/src/test/java/org/epilogtool/core/EpitheliumTest.java @@ -0,0 +1,85 @@ +package org.epilogtool.core; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.colomoto.biolqm.LogicalModel; +import org.epilogtool.FileUtils; +import org.epilogtool.common.Txt; +import org.epilogtool.io.FileIO; +import org.epilogtool.project.Project; +import org.junit.BeforeClass; +import org.junit.Test; + +public class EpitheliumTest { + private final static String YellowRedName = "YellowRed.sbml"; + private final static String GreenRedName = "GreenRed.sbml"; + + private static LogicalModel yellowRed; + private static LogicalModel greenRed; + + // Test if an sbml is properly loaded + @BeforeClass + public static void loadModelBeforeTests() throws IOException { + yellowRed = FileIO.loadSBMLModel(FileUtils.getResource("testModels", YellowRedName)); + greenRed = FileIO.loadSBMLModel(FileUtils.getResource("testModels", GreenRedName)); + } + + @Test + public void EpiListTest() throws IOException { + assertEquals(Project.getInstance().getEpitheliumList().size(), 16); + } + + // Tests if rollOver is being identified + // ColorModels EP0 = Torus + // ColorModels EP1 = Rectangular + @Test + public void Ep0Test() throws IOException { + + // RollOver + assertEquals(Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getTopology().getRollOver() + .toString(), Txt.get("s_Rollover_B")); + + // Topology + assertEquals( + Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getTopology().getDescription(), + "Pointy-Odd"); + + // EpitheliumName + assertEquals(Project.getInstance().getEpitheliumList().get(0).getName(), "Epi_0"); + + // Dimensions + assertEquals(Project.getInstance().getEpitheliumList().get(0).getX(), 10); + assertEquals(Project.getInstance().getEpitheliumList().get(0).getY(), 10); + + // Models on Epithelium -> how many models on + List lModels = new ArrayList(); + lModels.add(yellowRed); + lModels.add(greenRed); + + List setLogicalModelFile = new ArrayList(); + for (LogicalModel m : Project.getInstance().getEpitheliumList().get(0).getEpitheliumGrid().getModelSet()) { + Project.getInstance().getProjectFeatures().getModelName(m); + if (Project.getInstance().getProjectFeatures().getModelName(m).equals(YellowRedName) + | Project.getInstance().getProjectFeatures().getModelName(m).equals(GreenRedName)) { + setLogicalModelFile.add(m); + } + } + assertEquals(setLogicalModelFile.size(), lModels.size()); + + // TODO + // InputDefinitions -> integration functions + } + + @Test + public void Ep1Test() throws IOException { + + // RollOver + assertEquals(Project.getInstance().getEpitheliumList().get(1).getEpitheliumGrid().getTopology().getRollOver() + .toString(), Txt.get("s_Rollover_N")); + + } +} diff --git a/src/test/java/org/epilogtool/core/InitialConditionTest.java b/src/test/java/org/epilogtool/core/InitialConditionTest.java new file mode 100644 index 0000000..4d47cc7 --- /dev/null +++ b/src/test/java/org/epilogtool/core/InitialConditionTest.java @@ -0,0 +1,40 @@ +package org.epilogtool.core; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; + +import org.epilogtool.FileUtils; +import org.epilogtool.io.FileIO; +import org.epilogtool.project.Project; +import org.junit.BeforeClass; +import org.junit.Test; + +public class InitialConditionTest { + private final static String filePepsName = "ColorModels.peps"; + + @BeforeClass + public static void loadModelBeforeTests() throws IOException { + File filePeps = FileUtils.getResource("testProjects", filePepsName); + FileIO.loadPEPS(filePeps.getAbsolutePath()); + } + + @Test + public void initialConditions() { + // Tests 1) if the initial condition is properly read; 2) if the percentage is + // properly measured + Epithelium epi = Project.getInstance().getEpitheliumList().get(0); + + byte b; + + b = epi.getEpitheliumGrid().getCellValue(0, 0, "Red"); + assertEquals(b, (byte) 0); + + b = epi.getEpitheliumGrid().getCellValue(9, 9, "Red"); + assertEquals(b, (byte) 1); + + String strPercentage = epi.getEpitheliumGrid().getPercentage("Red"); + assertEquals(strPercentage, "(1 : 59%)"); + } +} diff --git a/src/test/java/org/epilogtool/core/IntegrationFunctionsTest.java b/src/test/java/org/epilogtool/core/IntegrationFunctionsTest.java new file mode 100644 index 0000000..030c8be --- /dev/null +++ b/src/test/java/org/epilogtool/core/IntegrationFunctionsTest.java @@ -0,0 +1,76 @@ +package org.epilogtool.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import org.colomoto.biolqm.LogicalModel; +import org.colomoto.biolqm.NodeInfo; +import org.epilogtool.FileUtils; +import org.epilogtool.io.FileIO; +import org.epilogtool.project.Project; +import org.junit.BeforeClass; +import org.junit.Test; + +public class IntegrationFunctionsTest { + private final static String YellowRedName = "YellowRed.sbml"; + private final static String GreenRedName = "GreenRed.sbml"; + private static LogicalModel YellowRed; + private static LogicalModel GreenRed; + + @BeforeClass + public static void loadModelBeforeTests() throws IOException { + + File fYellowRed = FileUtils.getResource("testModels", YellowRedName); + File fGreenRed = FileUtils.getResource("testModels", GreenRedName); + + YellowRed = FileIO.loadSBMLModel(fYellowRed); + GreenRed = FileIO.loadSBMLModel(fGreenRed); + + } + + @Test + public void test1() { + + Set integrationInputs = new HashSet(); + + integrationInputs.add(YellowRed.getComponent("Yellow")); + integrationInputs.add(GreenRed.getComponent("Green")); + + String strIntFunctions = "[Yellow, Green]"; + String strIntFunctions_2 = "[Green, Yellow]"; + boolean bFlag = true; + + // Test if the integration inputs are correct + if ((Project.getInstance().getEpitheliumList().get(0).getIntegrationNodes().toString().equals(strIntFunctions) + || (Project.getInstance().getEpitheliumList().get(0).getIntegrationNodes().toString() + .equals(strIntFunctions_2)))) { + assertTrue(bFlag); + } + + // Test if the integration functions are correct + Set strIntegrationFunctions_ctr = new HashSet(); + strIntegrationFunctions_ctr.add("{Red [1]}"); + strIntegrationFunctions_ctr.add("{Red [0:20]}"); + + Set strIntegrationFunctions = new HashSet(); + for (NodeInfo nodeInt : integrationInputs) { + // System.out.println(nodeInt); + + NodeInfo node = Project.getInstance().getEpitheliumList().get(0).getComponentUsed(nodeInt.getNodeID()); + + ComponentIntegrationFunctions cif = Project.getInstance().getEpitheliumList().get(0) + .getIntegrationFunctions().getAllIntegrationFunctions().get(node); + // System.out.println(Project.getInstance().getEpitheliumList().get(0).getIntegrationFunctions().getAllIntegrationFunctions().get(node)); + for (String strIntFunction : cif.getFunctions()) { + strIntegrationFunctions.add(strIntFunction); + } + } + assertEquals(strIntegrationFunctions, strIntegrationFunctions_ctr); + } + +} diff --git a/src/test/java/org/epilogtool/core/LoadProjectTest.java b/src/test/java/org/epilogtool/core/LoadProjectTest.java new file mode 100644 index 0000000..e352df7 --- /dev/null +++ b/src/test/java/org/epilogtool/core/LoadProjectTest.java @@ -0,0 +1,75 @@ +package org.epilogtool.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.util.Set; + +import org.epilogtool.FileUtils; +import org.epilogtool.io.FileIO; +import org.epilogtool.notification.NotificationManager; +import org.epilogtool.project.Project; +import org.junit.BeforeClass; +import org.junit.Test; + +public class LoadProjectTest { + + private final static String filePepsName = "ColorModels.peps"; + private final static String noConfigPepsName = "NoConfig.peps"; + private final static String noSBMLPepsName = "NoSBML.peps"; + + // Test if a project (Peps file) is properly loaded + + @BeforeClass + public static void setUp() { + NotificationManager.setGUI(false); + } + + @Test + public void projectNotFound() { + try { + FileIO.loadPEPS("bla"); + fail("Loaded a fake PEPS - should have failed"); + } catch (Exception e) { + } + } + + @Test + public void configNotFound() { + File noConfigPepsFile = FileUtils.getResource("testProjects", noConfigPepsName); + try { + assertFalse(FileIO.loadPEPS(noConfigPepsFile.getAbsolutePath())); + } catch (Exception e) { + fail("Loaded a PEPS without config.txt - should have returned false"); + } + } + + @Test + public void sbmlNotFound() throws IOException { + File noSBMLPepsFile = FileUtils.getResource("testProjects", noSBMLPepsName); + + // TODO: 1 peps com config.txt e sem .sbml + // noSBMLPepsFile + } + + @Test + public void loadProjectTest() throws IOException { + File filePeps = FileUtils.getResource("testProjects", filePepsName); + + // Good PEPS with SBML files + try { + assertTrue(FileIO.loadPEPS(filePeps.getAbsolutePath())); + } catch (Exception e) { + fail("Loading a PEPS with config.txt - should have returned true"); + } + Set sModels = Project.getInstance().getModelNames(); + assertEquals(sModels.size(), 3); + assertTrue(sModels.contains("GreenRed.sbml")); + assertTrue(sModels.contains("GreenBlue.sbml")); + assertTrue(sModels.contains("YellowRed.sbml")); + } +} diff --git a/src/test/java/org/epilogtool/core/ModelUpdateTest.java b/src/test/java/org/epilogtool/core/ModelUpdateTest.java new file mode 100644 index 0000000..99f0a96 --- /dev/null +++ b/src/test/java/org/epilogtool/core/ModelUpdateTest.java @@ -0,0 +1,47 @@ +package org.epilogtool.core; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; + +import org.colomoto.biolqm.LogicalModel; +import org.epilogtool.FileUtils; +import org.epilogtool.common.EnumRandomSeed; +import org.epilogtool.io.FileIO; +import org.epilogtool.project.Project; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ModelUpdateTest { + private final static String filePepsName = "ColorModels.peps"; + + @BeforeClass + public static void loadModelBeforeTests() throws IOException { + File filePeps = FileUtils.getResource("testProjects", filePepsName); + FileIO.loadPEPS(filePeps.getAbsolutePath()); + } + + @Test + public void cellularModelUpdate() { + Epithelium epi = Project.getInstance().getEpitheliumList().get(0); + LogicalModel m = epi.getModel(0, 0); + assertEquals(epi.getPriorityClasses(m).getClassVars(0).toString(), "[Yellow, Red]"); + + // TODO: get a model with more than one component + } + + @Test + public void epitheliumModelUpdate() { + // alpha + assertEquals(Project.getInstance().getEpitheliumList().get(0).getUpdateSchemeInter().getAlpha(), (float) 0, 96); + + // Random seed + assertEquals(Project.getInstance().getEpitheliumList().get(0).getUpdateSchemeInter().getRandomSeedType(), + EnumRandomSeed.RANDOM); + + // Updated cells + assertEquals(Project.getInstance().getEpitheliumList().get(0).getUpdateSchemeInter().getUpdateCells(), + (UpdateCells.fromString("Only updatable cells"))); + } +} diff --git a/src/test/java/org/epilogtool/core/NeighboursTest.java b/src/test/java/org/epilogtool/core/NeighboursTest.java new file mode 100644 index 0000000..c7cf5b6 --- /dev/null +++ b/src/test/java/org/epilogtool/core/NeighboursTest.java @@ -0,0 +1,131 @@ +package org.epilogtool.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.epilogtool.FileUtils; +import org.epilogtool.common.Tuple2D; +import org.epilogtool.io.FileIO; +import org.epilogtool.project.Project; +import org.junit.BeforeClass; +import org.junit.Test; + +public class NeighboursTest { + private final static String filePepsName = "ColorModels.peps"; + + private Map, Map>>> relativeNeighboursCache = new HashMap, Map>>>(); + + @BeforeClass + public static void loadModelBeforeTests() throws IOException { + File filePeps = FileUtils.getResource("testProjects", filePepsName); + FileIO.loadPEPS(filePeps.getAbsolutePath()); + } + + public void neighbours(int index, List neighboursNumber, int x, int y, int max) { + + // int minSign = 1; + for (int maxSign = 0; maxSign < max; maxSign++) { + + // verify cumulative distances + int minSign = 1; + Tuple2D rangePair = new Tuple2D(minSign, maxSign); + Tuple2D rangeList_aux = new Tuple2D(0, (minSign - 1 > 0) ? minSign - 1 : 0); + + Set> posNeighbours = Project.getInstance().getEpitheliumList().get(index) + .getEpitheliumGrid() + .getPositionNeighbours(this.relativeNeighboursCache, rangeList_aux, rangePair, minSign, x, y); + + int number = 0; + for (int ind = 0; ind <= maxSign; ind++) { + number = number + neighboursNumber.get(ind); + } + + assertEquals(posNeighbours.size(), number); + + // verify exact distances + // must increase the value of minSig to have exactly the same number of + // neighbours + + minSign = maxSign; + rangePair = new Tuple2D(minSign, maxSign); + rangeList_aux = new Tuple2D(0, (minSign - 1 > 0) ? minSign - 1 : 0); + posNeighbours = Project.getInstance().getEpitheliumList().get(index).getEpitheliumGrid() + .getPositionNeighbours(this.relativeNeighboursCache, rangeList_aux, rangePair, minSign, x, y); + + // System.out.println(posNeighbours); + number = neighboursNumber.get(maxSign); + if (minSign == 0) + number = 1; + assertEquals(posNeighbours.size(), number); + } + + } + + public void neighbourRange(int index, int minSign, int maxSign, int x, int y, int expectedNumber) { + + Tuple2D rangePair = new Tuple2D(minSign, maxSign); + Tuple2D rangeList_aux = new Tuple2D(0, (minSign - 1 > 0) ? minSign - 1 : 0); + + Set> posNeighbours = Project.getInstance().getEpitheliumList().get(index).getEpitheliumGrid() + .getPositionNeighbours(this.relativeNeighboursCache, rangeList_aux, rangePair, minSign, x, y); + + assertEquals(posNeighbours.size(), expectedNumber); + + } + + public boolean neighbourPresent(int index, int minSign, int maxSign, int x, int y, int Nx, int Ny) { + Tuple2D rangePair = new Tuple2D(minSign, maxSign); + Tuple2D rangeList_aux = new Tuple2D(0, (minSign - 1 > 0) ? minSign - 1 : 0); + + Set> posNeighbours = Project.getInstance().getEpitheliumList().get(index).getEpitheliumGrid() + .getPositionNeighbours(this.relativeNeighboursCache, rangeList_aux, rangePair, minSign, x, y); + + return posNeighbours.contains(new Tuple2D(Nx, Ny)); + } + + @Test + public void neighbours() { + + // ***************PointyOdd + neighbours(0, Arrays.asList(0, 6, 12, 18, 24, 23, 12, 4), 0, 0, 8); // Torus + neighbourRange(0, 0, -1, 0, 0, 100); // Torus range[0:] + neighbourRange(0, 1, -1, 0, 0, 99); // Torus range[1:] + neighbourRange(0, 1, 40, 0, 0, 99); // Torus range[1:40] + + neighbours(1, Arrays.asList(0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 9, 7, 5, 3, 1), 0, 0, 14); // rectangular + neighbours(2, Arrays.asList(0, 4, 7, 10, 13, 15, 14, 13, 12, 11), 0, 0, 9); // Horizontal + neighbours(3, Arrays.asList(0, 3, 7, 9, 13, 12, 10, 10, 10, 10, 9, 5, 1), 0, 0, 10); // vertical + + // ***************PointyEven + neighbours(4, Arrays.asList(0, 6, 12, 18, 24, 23, 12, 4), 0, 0, 8); // Torus + neighbours(5, Arrays.asList(0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 9, 7, 5, 3, 1), 0, 0, 14); // rectangular + neighbours(6, Arrays.asList(0, 4, 7, 10, 13, 15, 14, 13, 12, 11), 0, 0, 9); // Horizontal + neighbours(7, Arrays.asList(0, 3, 7, 9, 13, 12, 10, 10, 10, 10, 9, 5, 1), 0, 0, 10); // vertical + + // ***************FlatOdd + neighbours(8, Arrays.asList(0, 6, 12, 18, 24, 23, 12, 4), 0, 0, 8); // Torus + neighbours(9, Arrays.asList(0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 9, 7, 5, 3, 1), 0, 0, 14); // rectangular + neighbours(10, Arrays.asList(0, 4, 7, 10, 13, 15, 14, 13, 12, 11), 0, 0, 9); // Horizontal + neighbours(11, Arrays.asList(0, 3, 7, 9, 13, 12, 10, 10, 10, 10, 9, 5, 1), 0, 0, 10); // vertical + + // ***************FlatEven + neighbours(12, Arrays.asList(0, 6, 12, 18, 24, 23, 12, 4), 0, 0, 8); // Torus + neighbours(13, Arrays.asList(0, 2, 4, 5, 7, 8, 10, 11, 13, 14, 9, 7, 5, 3, 1), 0, 0, 14); // rectangular + neighbours(14, Arrays.asList(0, 4, 7, 10, 13, 15, 14, 13, 12, 11), 0, 0, 9); // Horizontal + neighbours(15, Arrays.asList(0, 3, 7, 9, 13, 12, 10, 10, 10, 10, 9, 5, 1), 0, 0, 10); // vertical + + // TODO: verify neighbours for intermediate values + assertFalse(neighbourPresent(0, 2, 4, 0, 0, 0, 0)); + assertTrue(neighbourPresent(0, 2, 4, 0, 0, 0, 2)); + + } +} diff --git a/src/test/java/org/epilogtool/core/PerturbationTest.java b/src/test/java/org/epilogtool/core/PerturbationTest.java new file mode 100644 index 0000000..2c0d999 --- /dev/null +++ b/src/test/java/org/epilogtool/core/PerturbationTest.java @@ -0,0 +1,48 @@ +package org.epilogtool.core; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; + +import org.colomoto.biolqm.LogicalModel; +import org.colomoto.biolqm.modifier.perturbation.AbstractPerturbation; +import org.colomoto.biolqm.modifier.perturbation.RangePerturbation; +import org.epilogtool.FileUtils; +import org.epilogtool.io.FileIO; +import org.epilogtool.project.Project; +import org.junit.BeforeClass; +import org.junit.Test; + +public class PerturbationTest { + private final static String filePepsName = "ColorModels.peps"; + + @BeforeClass + public static void loadModelBeforeTests() throws IOException { + File filePeps = FileUtils.getResource("testProjects", filePepsName); + FileIO.loadPEPS(filePeps.getAbsolutePath()); + } + + @Test + public void setPerturbation() { + Epithelium epi = Project.getInstance().getEpitheliumList().get(0); + LogicalModel m = epi.getModel(0, 0); + EpitheliumCell epicell = new EpitheliumCell(m); + AbstractPerturbation rp = new RangePerturbation(m.getComponents().get(0), 0, 1); + epicell.setPerturbation(rp); + assertEquals(rp, epicell.getPerturbation()); + } + + @Test + public void perturbations() { + // Tests 1) if the perturbations are properly defined + Epithelium epi = Project.getInstance().getEpitheliumList().get(0); + + assertEquals(epi.getEpitheliumGrid().getPerturbation(4, 5).getStringRepresentation(), "Red%0"); + assertEquals(epi.getEpitheliumGrid().getPerturbation(5, 4).getStringRepresentation(), "Red%1"); + assertEquals(epi.getEpitheliumGrid().getPerturbation(0, 0), null); + + // TODO: get a model with more than one value to check the range + } + +} diff --git a/src/test/java/org/epilogtool/core/SimulationTest.java b/src/test/java/org/epilogtool/core/SimulationTest.java new file mode 100644 index 0000000..bcddb50 --- /dev/null +++ b/src/test/java/org/epilogtool/core/SimulationTest.java @@ -0,0 +1,30 @@ +package org.epilogtool.core; + +import java.io.File; +import java.io.IOException; + +import org.epilogtool.FileUtils; +import org.epilogtool.io.FileIO; +import org.junit.BeforeClass; +import org.junit.Test; + +public class SimulationTest { + private final static String filePepsName = "ColorModels.peps"; + + @BeforeClass + public static void loadModelBeforeTests() throws IOException { + File filePeps = FileUtils.getResource("testProjects", filePepsName); + FileIO.loadPEPS(filePeps.getAbsolutePath()); + } + + @Test + public void simulationTest() { + + // TODO + // verify nextStep - Random Seed. everything is different + // verify terminal cycle + // verify stable pattern + // verify perturb model + + } +}