Commit 72354611 authored by Philipp Görick's avatar Philipp Görick

Refactored FlattenAlgorithm test to compare result with an EMAComponentInstanceSymbol

parent 1e370711
Pipeline #101090 failed with stages
in 12 minutes and 17 seconds
......@@ -25,6 +25,7 @@ import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.stream.file.FileSinkImages;
import org.junit.Assert;
import org.junit.Test;
import smile.clustering.DBSCAN;
import smile.clustering.SpectralClustering;
......@@ -126,91 +127,6 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
}
@Test
public void testFlattenAlgorithm1(){
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.overallSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol);
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(10, subComponents.size());
assertEquals(20, connectors.size());
}
@Test
public void testFlattenAlgorithm1ShortNames(){
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.overallSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol, new HashMap<>());
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(10, subComponents.size());
assertEquals(20, connectors.size());
}
@Test
public void testFlattenAlgorithm2(){
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.spanningSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol);
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(20, subComponents.size());
assertEquals(40, connectors.size());
}
@Test
public void testFlattenAlgorithm2ShortNames() {
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.spanningSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol, new HashMap<>());
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(20, subComponents.size());
assertEquals(40, connectors.size());
}
@Test
public void testFlattenAlgorithmWithLevels() {
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.spanningSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol, new HashMap<>(), 2);
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(4, subComponents.size());
assertEquals(24, connectors.size());
}
// todo: gotta move this thing later, just temporarily here for testing purposes
public static Dataset[] getClustering(Dataset data, SparseMatrix matrix) {
......@@ -986,4 +902,6 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
assertEquals(2, labels.length);
assertTrue(labels[0] != labels[1]);
}
}
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
import de.monticore.lang.monticar.generator.middleware.clustering.FlattenArchitecture;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
public class FlattenAlgorithmTest {
public static final String TEST_PATH = "src/test/resources/";
@Test
public void testFlattenAlgorithm1(){
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.overallSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol);
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(10, subComponents.size());
assertEquals(20, connectors.size());
}
@Test
public void testFlattenAlgorithm1ShortNames(){
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.overallSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol, new HashMap<>());
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(10, subComponents.size());
assertEquals(20, connectors.size());
EMAComponentInstanceSymbol testComponentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.overallSystemShortNameTest", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(testComponentInstanceSymbol);
assertEqualEMAComponentInstanceSymbol(testComponentInstanceSymbol, newComponentInstanceSymbol);
}
@Test
public void testFlattenAlgorithm2(){
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.spanningSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol);
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(20, subComponents.size());
assertEquals(40, connectors.size());
}
@Test
public void testFlattenAlgorithm2ShortNames() {
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.spanningSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol, new HashMap<>());
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(20, subComponents.size());
assertEquals(40, connectors.size());
EMAComponentInstanceSymbol testComponentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.spanningSystemShortNameTest", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(testComponentInstanceSymbol);
assertEqualEMAComponentInstanceSymbol(testComponentInstanceSymbol, newComponentInstanceSymbol);
}
@Test
public void testFlattenAlgorithmWithLevels() {
TaggingResolver taggingResolver = AbstractSymtabTest.createSymTabAndTaggingResolver(TEST_PATH);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver
.<EMAComponentInstanceSymbol>resolve("lab.spanningSystem", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
EMAComponentInstanceSymbol newComponentInstanceSymbol = FlattenArchitecture
.flattenArchitecture(componentInstanceSymbol, new HashMap<>(), 2);
assertNotNull(newComponentInstanceSymbol);
Collection<EMAComponentInstanceSymbol> subComponents = newComponentInstanceSymbol.getSubComponents();
Collection<EMAConnectorInstanceSymbol> connectors = newComponentInstanceSymbol.getConnectorInstances();
assertEquals(4, subComponents.size());
assertEquals(24, connectors.size());
}
private static void assertEqualEMAComponentInstanceSymbol(EMAComponentInstanceSymbol symbol1, EMAComponentInstanceSymbol symbol2) {
List<String> symbol1Subcomponents = new ArrayList();
List<String> symbol2Subcomponents = new ArrayList();
List<String> symbol1Ports = new ArrayList();
List<String> symbol2Ports = new ArrayList();
List<String> symbol1Connectors = new ArrayList();
List<String> symbol2Connectors = new ArrayList();
for (EMAComponentInstanceSymbol s : symbol1.getSubComponents()) {
symbol1Subcomponents.add(s.getName());
}
for (EMAComponentInstanceSymbol s : symbol2.getSubComponents()) {
symbol2Subcomponents.add(s.getName());
}
for (EMAConnectorInstanceSymbol c : symbol1.getConnectorInstances()) {
symbol1Connectors.add(c.getName());
}
for (EMAConnectorInstanceSymbol c : symbol2.getConnectorInstances()) {
symbol2Connectors.add(c.getName());
}
for (EMAPortInstanceSymbol p : symbol1.getPortInstanceList()) {
symbol1Ports.add(p.getName());
}
for (EMAPortInstanceSymbol p : symbol2.getPortInstanceList()) {
symbol2Ports.add(p.getName());
}
assertTrue(symbol1Ports.containsAll(symbol2Ports));
assertTrue(symbol2Ports.containsAll(symbol1Ports));
assertTrue(symbol1Connectors.containsAll(symbol2Connectors));
assertTrue(symbol2Connectors.containsAll(symbol1Connectors));
assertTrue(symbol1Subcomponents.containsAll(symbol2Subcomponents));
assertTrue(symbol2Subcomponents.containsAll(symbol1Subcomponents));
}
}
package lab;
component overallSystemShortNameTest {
ports
in Q input[4],
out Q output[4];
instance Alex alex;
instance DinhAn dinhAn;
instance Philipp philipp;
instance Michael michael;
instance Combine combine;
instance Alex alex1;
instance DinhAn dinhAn1;
instance Philipp philipp1;
instance Michael michael1;
instance Combine combine1;
connect input[1] -> alex.input;
connect input[2] -> dinhAn.input;
connect input[3] -> philipp.input;
connect input[4] -> michael.input;
connect alex.out1 -> combine.in1;
connect dinhAn.out1 -> combine.in2;
connect philipp.out1 -> combine.in3;
connect michael.out1 -> combine.in4;
connect combine.out1 -> alex1.input;
connect combine.out1 -> dinhAn1.input;
connect combine.out1 -> philipp1.input;
connect combine.out1 -> michael1.input;
connect alex1.out1 -> combine1.in1;
connect dinhAn1.out1 -> combine1.in2;
connect philipp1.out1 -> combine1.in3;
connect michael1.out1 -> combine1.in4;
connect combine1.out1 -> output[1];
connect combine1.out1 -> output[2];
connect combine1.out1 -> output[3];
connect combine1.out1 -> output[4];
}
package lab;
component spanningSystemShortNameTest{
ports in Q input,
out Q output;
instance Alex alex;
instance DinhAn dinhAn;
instance Philipp philipp;
instance Michael michael;
instance Combine combine;
instance Alex alex1;
instance DinhAn dinhAn1;
instance Philipp philipp1;
instance Michael michael1;
instance Combine combine1;
instance Alex alex2;
instance DinhAn dinhAn2;
instance Philipp philipp2;
instance Michael michael2;
instance Combine combine2;
instance Alex alex3;
instance DinhAn dinhAn3;
instance Philipp philipp3;
instance Michael michael3;
instance Combine combine3;
connect input -> alex.input;
connect input -> dinhAn.input;
connect input -> philipp.input;
connect input -> michael.input;
connect input -> alex2.input;
connect input -> dinhAn2.input;
connect input -> philipp2.input;
connect input -> michael2.input;
connect combine1.out1 -> output;
connect combine1.out1 -> output;
connect combine1.out1 -> output;
connect combine1.out1 -> output;
connect combine3.out1 -> output;
connect combine3.out1 -> output;
connect combine3.out1 -> output;
connect combine3.out1 -> output;
connect alex.out1 -> combine.in1;
connect dinhAn.out1 -> combine.in2;
connect philipp.out1 -> combine.in3;
connect michael.out1 -> combine.in4;
connect combine.out1 -> alex1.input;
connect combine.out1 -> dinhAn1.input;
connect combine.out1 -> philipp1.input;
connect combine.out1 -> michael1.input;
connect alex1.out1 -> combine1.in1;
connect dinhAn1.out1 -> combine1.in2;
connect philipp1.out1 -> combine1.in3;
connect michael1.out1 -> combine1.in4;
connect alex2.out1 -> combine2.in1;
connect dinhAn2.out1 -> combine2.in2;
connect philipp2.out1 -> combine2.in3;
connect michael2.out1 -> combine2.in4;
connect combine2.out1 -> alex3.input;
connect combine2.out1 -> dinhAn3.input;
connect combine2.out1 -> philipp3.input;
connect combine2.out1 -> michael3.input;
connect alex3.out1 -> combine3.in1;
connect dinhAn3.out1 -> combine3.in2;
connect philipp3.out1 -> combine3.in3;
connect michael3.out1 -> combine3.in4;
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment