From e4b996d16885e52a6dfcacc20a94bd7eea1f8874 Mon Sep 17 00:00:00 2001 From: rgudwin Date: Wed, 25 Sep 2024 18:55:31 -0300 Subject: [PATCH] Added some tests --- build.gradle | 6 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../cst/{util => support}/TestCodelet.java | 2 +- .../TestComplexMemoryObjectInfo.java | 2 +- .../cst/util/CodeletsProfilerTest.java | 402 ------------------ .../br/unicamp/cst/util/MindViewerTest.java | 1 + .../cst/util/viewer/AnalysisPanelTest.java | 2 +- .../cst/util/viewer/MemoryInspectorTest.java | 2 +- .../cst/util/viewer/MemoryViewerTest.java | 2 +- 9 files changed, 10 insertions(+), 411 deletions(-) rename src/test/java/br/unicamp/cst/{util => support}/TestCodelet.java (96%) rename src/test/java/br/unicamp/cst/{util => support}/TestComplexMemoryObjectInfo.java (99%) delete mode 100644 src/test/java/br/unicamp/cst/util/CodeletsProfilerTest.java diff --git a/build.gradle b/build.gradle index b5e7b94..e42fae3 100644 --- a/build.gradle +++ b/build.gradle @@ -34,8 +34,8 @@ configurations { } dependencies { - //api('com.github.CST-Group:cst:8c66269') - api('com.github.CST-Group:cst-bindings:1.0.6') + api('com.github.CST-Group:cst:1.4.2') + api('com.github.CST-Group:cst-bindings:1.0.8') //api ':cst-bindings:1.0.6-full' api group: 'org.jfree', name: 'jfreechart', version: '1.0.19' api 'com.soartech:jsoar-core:4.1.3' @@ -48,7 +48,7 @@ dependencies { api group: 'net.sf.jung', name: 'jung-api', version: '2.0.1' api 'com.github.rosjava:rosjava_core:0.3.7' api 'org.ros.rosjava_bootstrap:message_generation:0.3.3' - + testImplementation 'com.github.CST-Group:cst:1.4.2' testImplementation 'com.1stleg:jnativehook:2.1.0' testImplementation group: 'junit', name: 'junit', version: '4.12' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e411586..1e2fbf0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/test/java/br/unicamp/cst/util/TestCodelet.java b/src/test/java/br/unicamp/cst/support/TestCodelet.java similarity index 96% rename from src/test/java/br/unicamp/cst/util/TestCodelet.java rename to src/test/java/br/unicamp/cst/support/TestCodelet.java index c3502c8..f46f23c 100644 --- a/src/test/java/br/unicamp/cst/util/TestCodelet.java +++ b/src/test/java/br/unicamp/cst/support/TestCodelet.java @@ -8,7 +8,7 @@ * Contributors: * K. Raizer, A. L. O. Paraense, E. M. Froes, R. R. Gudwin - initial API and implementation ***********************************************************************************************/ -package br.unicamp.cst.util; +package br.unicamp.cst.support; import br.unicamp.cst.core.entities.Codelet; diff --git a/src/test/java/br/unicamp/cst/util/TestComplexMemoryObjectInfo.java b/src/test/java/br/unicamp/cst/support/TestComplexMemoryObjectInfo.java similarity index 99% rename from src/test/java/br/unicamp/cst/util/TestComplexMemoryObjectInfo.java rename to src/test/java/br/unicamp/cst/support/TestComplexMemoryObjectInfo.java index db961cc..c5e0ae7 100644 --- a/src/test/java/br/unicamp/cst/util/TestComplexMemoryObjectInfo.java +++ b/src/test/java/br/unicamp/cst/support/TestComplexMemoryObjectInfo.java @@ -8,7 +8,7 @@ * Contributors: * K. Raizer, A. L. O. Paraense, E. M. Froes, R. R. Gudwin - initial API and implementation * **********************************************************************************************/ -package br.unicamp.cst.util; +package br.unicamp.cst.support; import java.util.ArrayList; import java.util.Date; diff --git a/src/test/java/br/unicamp/cst/util/CodeletsProfilerTest.java b/src/test/java/br/unicamp/cst/util/CodeletsProfilerTest.java deleted file mode 100644 index 1c22176..0000000 --- a/src/test/java/br/unicamp/cst/util/CodeletsProfilerTest.java +++ /dev/null @@ -1,402 +0,0 @@ -/*********************************************************************************************** - * Copyright (c) 2012 DCA-FEEC-UNICAMP - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * K. Raizer, A. L. O. Paraense, E. M. Froes, R. R. Gudwin - initial API and implementation - ***********************************************************************************************/ -package br.unicamp.cst.util; - -import static org.junit.Assert.assertEquals; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.google.gson.JsonArray; -import com.google.gson.JsonParser; - -import br.unicamp.cst.core.entities.Codelet; -import br.unicamp.cst.core.entities.MemoryContainer; -import br.unicamp.cst.core.entities.MemoryObject; -import br.unicamp.cst.core.entities.Mind; -import br.unicamp.cst.support.CodeletsProfiler.FileFormat; -//import br.unicamp.cst.util.CodeletsProfiler.CodeletTrack; -//import br.unicamp.cst.util.CodeletsProfiler.FileFormat; - -public class CodeletsProfilerTest { - - private static String filePath = "profile/"; - private String fileNameCSV_1 = "file_in_csv_1.txt"; - private String fileNameJSON_1 = "file_in_json_1.txt"; - private String fileNameJSON_2 = "file_in_json_2.txt"; - private final static String comma = ","; - private final static String csvSeparator = ";"; - - - @BeforeClass - public static void beforeAllTestMethods() { - } - - @AfterClass - public static void afterAllTestMethods() { - try - { - File f= new File(filePath); - f.delete(); - } - catch(Exception e) { - e.printStackTrace(); - } - - } - - private List> readCSVFile(String fileName) { - BufferedReader br = null; - List> records = new ArrayList<>(); - try { - br = new BufferedReader(new FileReader(fileName)); - String line = br.readLine(); - - while ((line = br.readLine()) != null) { - String[] values = line.split(comma); - records.add(Arrays.asList(values)); - } - } catch (Exception e) { - - e.printStackTrace(); - - } finally { - try { - br.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - return records; - } - - private JsonArray readJSONFile(String fileName) { - JsonArray data = null; - BufferedReader br = null; - try - { - br = new BufferedReader(new FileReader(fileName)); - JsonParser parser = new JsonParser(); - data = parser.parse(br).getAsJsonArray(); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - br.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - return data; - } - - private void deleteFile(String fileName) { - try - { - File f= new File(fileName); - f.delete(); - } - catch(Exception e) { - e.printStackTrace(); - } - } - - private void assertsCodeletNameInCSVFile(List> textCSV, String codeletName) { - for (List item : textCSV) { - for (String line : item) { - String[] values = line.split(csvSeparator); - assertEquals(values[2], codeletName); - } - - } - } - - private void assertsCodeletNameInJSONFile(JsonArray codeletsTrack, String codeletName) { - for (int i = 0; i < (codeletsTrack.size() - 1); i++) { - assertEquals(codeletsTrack.get(i).getAsJsonObject().get("codeletName").getAsString(), codeletName); - } - } - - @Test - public void testCodeletsProfiler() throws InterruptedException { - - Mind m = new Mind(); - MemoryObject m1 = m.createMemoryObject("M1", 0.12); - MemoryObject m2 = m.createMemoryObject("M2", 0.32); - MemoryObject m3 = m.createMemoryObject("M3", 0.44); - MemoryObject m4 = m.createMemoryObject("M4", 0.52); - MemoryObject m5 = m.createMemoryObject("M5", 0.12); - MemoryContainer m6 = m.createMemoryContainer("C1"); - MemoryContainer m7 = m.createMemoryContainer("C2"); - TestComplexMemoryObjectInfo mComplex = new TestComplexMemoryObjectInfo(); - mComplex.complextest = new TestComplexMemoryObjectInfo(); - for (int i=0;i<3;i++) - mComplex.complextestarray[i] = new TestComplexMemoryObjectInfo(); - MemoryObject mo = new MemoryObject(); - mo.setType("TestObject"); - mo.setI(mComplex); - m7.setI(0.55, 0.23); - m6.setI(0.33, 0.22); - m6.setI(0.12, 0.13); - m6.setI(m7); - Codelet c = new TestCodelet("Codelet 1"); - c.addInput(m1); - c.addInput(m2); - c.addOutput(m3); - c.addOutput(m4); - c.addBroadcast(m5); - c.addBroadcast(mo); - c.setCodeletProfiler(filePath, fileNameCSV_1, "Mind 1", 10, null, FileFormat.CSV); - m.insertCodelet(c); - Codelet c2 = new TestCodelet("Codelet 2"); - c2.addInput(m4); - c2.addInput(m5); - c2.addOutput(m6); - c2.addOutput(m3); - c2.addBroadcast(m5); - c2.setCodeletProfiler(filePath, fileNameJSON_1, "Mind 1", 10, null, FileFormat.JSON); - m.insertCodelet(c2); - m.start(); - Thread.sleep(2000); - m.shutDown(); - - List> textCSV = readCSVFile(filePath+fileNameCSV_1); - assertsCodeletNameInCSVFile(textCSV, "Codelet 1"); - - deleteFile(filePath+fileNameCSV_1); - - JsonArray codeletsTrack = readJSONFile(filePath+fileNameJSON_1); - assertsCodeletNameInJSONFile(codeletsTrack, "Codelet 2"); - - deleteFile(filePath+fileNameJSON_1); - - } - - @Test - public void testCodeletsProfiler2() throws InterruptedException { - Mind m = new Mind(); - MemoryObject m1 = m.createMemoryObject("M1", 0.12); - MemoryObject m2 = m.createMemoryObject("M2", 0.32); - MemoryObject m3 = m.createMemoryObject("M3", 0.44); - MemoryObject m4 = m.createMemoryObject("M4", 0.52); - MemoryObject m5 = m.createMemoryObject("M5", 0.12); - MemoryContainer m6 = m.createMemoryContainer("C1"); - MemoryContainer m7 = m.createMemoryContainer("C2"); - TestComplexMemoryObjectInfo mComplex = new TestComplexMemoryObjectInfo(); - mComplex.complextest = new TestComplexMemoryObjectInfo(); - for (int i = 0; i < 3; i++) - mComplex.complextestarray[i] = new TestComplexMemoryObjectInfo(); - MemoryObject mo = new MemoryObject(); - mo.setType("TestObject"); - mo.setI(mComplex); - m7.setI(0.55, 0.23); - m6.setI(0.33, 0.22); - m6.setI(0.12, 0.13); - m6.setI(m7); - Codelet c = new TestCodelet("Codelet 1"); - c.addInput(m1); - c.addInput(m2); - c.addOutput(m3); - c.addOutput(m4); - c.addBroadcast(m5); - c.addBroadcast(mo); - c.setCodeletProfiler(filePath, fileNameJSON_1, "Mind 1", null, (long) 1000, FileFormat.JSON); - m.insertCodelet(c); - Codelet c2 = new TestCodelet("Codelet 2"); - c2.addInput(m4); - c2.addInput(m5); - c2.addOutput(m6); - c2.addOutput(m3); - c2.addBroadcast(m5); - c2.setCodeletProfiler(filePath, fileNameJSON_2, "Mind 1", null, (long) 1000, FileFormat.JSON); - m.insertCodelet(c2); - m.start(); - Thread.sleep(2000); - m.shutDown(); - - JsonArray codeletsTrack1 = readJSONFile(filePath+fileNameJSON_1); - assertsCodeletNameInJSONFile(codeletsTrack1, "Codelet 1"); - - deleteFile(filePath+fileNameJSON_1); - - JsonArray codeletsTrack2 = readJSONFile(filePath+fileNameJSON_2); - assertsCodeletNameInJSONFile(codeletsTrack2, "Codelet 2"); - - deleteFile(filePath+fileNameJSON_2); - - } - - @Test - public void testCodeletsProfiler3() throws InterruptedException { - Mind m = new Mind(); - MemoryObject m1 = m.createMemoryObject("M1", 0.12); - MemoryObject m2 = m.createMemoryObject("M2", 0.32); - MemoryObject m3 = m.createMemoryObject("M3", 0.44); - MemoryObject m4 = m.createMemoryObject("M4", 0.52); - MemoryObject m5 = m.createMemoryObject("M5", 0.12); - MemoryContainer m6 = m.createMemoryContainer("C1"); - MemoryContainer m7 = m.createMemoryContainer("C2"); - TestComplexMemoryObjectInfo mComplex = new TestComplexMemoryObjectInfo(); - mComplex.complextest = new TestComplexMemoryObjectInfo(); - for (int i = 0; i < 3; i++) - mComplex.complextestarray[i] = new TestComplexMemoryObjectInfo(); - MemoryObject mo = new MemoryObject(); - mo.setType("TestObject"); - mo.setI(mComplex); - m7.setI(0.55, 0.23); - m6.setI(0.33, 0.22); - m6.setI(0.12, 0.13); - m6.setI(m7); - Codelet c = new TestCodelet("Codelet 1"); - c.addInput(m1); - c.addInput(m2); - c.addOutput(m3); - c.addOutput(m4); - c.addBroadcast(m5); - c.addBroadcast(mo); - m.insertCodelet(c); - Codelet c2 = new TestCodelet("Codelet 2"); - c2.addInput(m4); - c2.addInput(m5); - c2.addOutput(m6); - c2.addOutput(m3); - c2.addBroadcast(m5); - c2.setCodeletProfiler(filePath, fileNameCSV_1, "Mind 1", null, (long) 1000, FileFormat.CSV); - m.insertCodelet(c2); - m.start(); - Thread.sleep(2000); - m.shutDown(); - - List> textCSV = readCSVFile(filePath+fileNameCSV_1); - assertsCodeletNameInCSVFile(textCSV, "Codelet 2"); - - deleteFile(filePath+fileNameCSV_1); - - } - - @Test - public void testCodeletsProfiler4() throws InterruptedException { - Mind m = new Mind(); - MemoryObject m1 = m.createMemoryObject("M1", 0.12); - MemoryObject m2 = m.createMemoryObject("M2", 0.32); - MemoryObject m3 = m.createMemoryObject("M3", 0.44); - MemoryObject m4 = m.createMemoryObject("M4", 0.52); - MemoryObject m5 = m.createMemoryObject("M5", 0.12); - MemoryContainer m6 = m.createMemoryContainer("C1"); - MemoryContainer m7 = m.createMemoryContainer("C2"); - TestComplexMemoryObjectInfo mComplex = new TestComplexMemoryObjectInfo(); - mComplex.complextest = new TestComplexMemoryObjectInfo(); - for (int i = 0; i < 3; i++) - mComplex.complextestarray[i] = new TestComplexMemoryObjectInfo(); - MemoryObject mo = new MemoryObject(); - mo.setType("TestObject"); - mo.setI(mComplex); - m7.setI(0.55, 0.23); - m6.setI(0.33, 0.22); - m6.setI(0.12, 0.13); - m6.setI(m7); - Codelet c = new TestCodelet("Codelet 1"); - c.addInput(m1); - c.addInput(m2); - c.addOutput(m3); - c.addOutput(m4); - c.addBroadcast(m5); - c.addBroadcast(mo); - c.setCodeletProfiler(filePath, fileNameJSON_1, "Mind 1", 5, null, FileFormat.JSON); - m.insertCodelet(c); - Codelet c2 = new TestCodelet("Codelet 2"); - c2.addInput(m4); - c2.addInput(m5); - c2.addOutput(m6); - c2.addOutput(m3); - c2.addBroadcast(m5); - c2.setCodeletProfiler(filePath, fileNameCSV_1, "Mind 1", 5, (long) 1000, FileFormat.CSV); - m.insertCodelet(c2); - m.start(); - Thread.sleep(2000); - m.shutDown(); - - JsonArray codeletsTrack = readJSONFile(filePath+fileNameJSON_1); - assertsCodeletNameInJSONFile(codeletsTrack, "Codelet 1"); - - deleteFile(filePath+fileNameJSON_1); - - List> textCSV = readCSVFile(filePath+fileNameCSV_1); - assertsCodeletNameInCSVFile(textCSV, "Codelet 2"); - - deleteFile(filePath+fileNameCSV_1); - - } - - @Test - public void testCodeletsProfiler5() throws InterruptedException { - Mind m = new Mind(); - MemoryObject m1 = m.createMemoryObject("M1", 0.12); - MemoryObject m2 = m.createMemoryObject("M2", 0.32); - MemoryObject m3 = m.createMemoryObject("M3", 0.44); - MemoryObject m4 = m.createMemoryObject("M4", 0.52); - MemoryObject m5 = m.createMemoryObject("M5", 0.12); - MemoryContainer m6 = m.createMemoryContainer("C1"); - MemoryContainer m7 = m.createMemoryContainer("C2"); - TestComplexMemoryObjectInfo mComplex = new TestComplexMemoryObjectInfo(); - mComplex.complextest = new TestComplexMemoryObjectInfo(); - for (int i = 0; i < 3; i++) - mComplex.complextestarray[i] = new TestComplexMemoryObjectInfo(); - MemoryObject mo = new MemoryObject(); - mo.setType("TestObject"); - mo.setI(mComplex); - m7.setI(0.55, 0.23); - m6.setI(0.33, 0.22); - m6.setI(0.12, 0.13); - m6.setI(m7); - Codelet c = new TestCodelet("Codelet 1"); - c.addInput(m1); - c.addInput(m2); - c.addOutput(m3); - c.addOutput(m4); - c.addBroadcast(m5); - c.addBroadcast(mo); - c.setCodeletProfiler(filePath, fileNameJSON_1, "Mind 1", null, null, FileFormat.JSON); - m.insertCodelet(c); - Codelet c2 = new TestCodelet("Codelet 2"); - c2.addInput(m4); - c2.addInput(m5); - c2.addOutput(m6); - c2.addOutput(m3); - c2.addBroadcast(m5); - c2.setCodeletProfiler(filePath, fileNameCSV_1, "Mind 1", null, null, FileFormat.CSV); - m.insertCodelet(c2); - m.start(); - Thread.sleep(2000); - m.shutDown(); - - JsonArray codeletsTrack = readJSONFile(filePath+fileNameJSON_1); - assertsCodeletNameInJSONFile(codeletsTrack, "Codelet 1"); - - deleteFile(filePath+fileNameJSON_1); - - List> textCSV = readCSVFile(filePath+fileNameCSV_1); - assertsCodeletNameInCSVFile(textCSV, "Codelet 2"); - - deleteFile(filePath+fileNameCSV_1); - - } - -} diff --git a/src/test/java/br/unicamp/cst/util/MindViewerTest.java b/src/test/java/br/unicamp/cst/util/MindViewerTest.java index e20a4e5..5030010 100644 --- a/src/test/java/br/unicamp/cst/util/MindViewerTest.java +++ b/src/test/java/br/unicamp/cst/util/MindViewerTest.java @@ -21,6 +21,7 @@ import br.unicamp.cst.core.entities.MemoryContainer; import br.unicamp.cst.core.entities.MemoryObject; import br.unicamp.cst.core.entities.Mind; +import br.unicamp.cst.support.*; /** * @author gudwin diff --git a/src/test/java/br/unicamp/cst/util/viewer/AnalysisPanelTest.java b/src/test/java/br/unicamp/cst/util/viewer/AnalysisPanelTest.java index 8975113..4961710 100644 --- a/src/test/java/br/unicamp/cst/util/viewer/AnalysisPanelTest.java +++ b/src/test/java/br/unicamp/cst/util/viewer/AnalysisPanelTest.java @@ -18,7 +18,7 @@ import br.unicamp.cst.support.CodeletsProfiler; import br.unicamp.cst.support.CodeletsProfiler.CodeletTrack; import br.unicamp.cst.support.InterfaceAdapter; -import br.unicamp.cst.util.TestCodelet; +import br.unicamp.cst.support.TestCodelet; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.stream.JsonReader; diff --git a/src/test/java/br/unicamp/cst/util/viewer/MemoryInspectorTest.java b/src/test/java/br/unicamp/cst/util/viewer/MemoryInspectorTest.java index ad40520..b116ed3 100644 --- a/src/test/java/br/unicamp/cst/util/viewer/MemoryInspectorTest.java +++ b/src/test/java/br/unicamp/cst/util/viewer/MemoryInspectorTest.java @@ -17,7 +17,7 @@ import java.awt.event.InputEvent; import static org.junit.Assert.assertEquals; -import br.unicamp.cst.util.TestComplexMemoryObjectInfo; +import br.unicamp.cst.support.TestComplexMemoryObjectInfo; import org.junit.Test; /** diff --git a/src/test/java/br/unicamp/cst/util/viewer/MemoryViewerTest.java b/src/test/java/br/unicamp/cst/util/viewer/MemoryViewerTest.java index e309b0d..13de505 100644 --- a/src/test/java/br/unicamp/cst/util/viewer/MemoryViewerTest.java +++ b/src/test/java/br/unicamp/cst/util/viewer/MemoryViewerTest.java @@ -16,7 +16,7 @@ import java.awt.Robot; import java.util.Random; -import br.unicamp.cst.util.TestComplexMemoryObjectInfo; +import br.unicamp.cst.support.TestComplexMemoryObjectInfo; import org.junit.Test; /**