Adds test for the pattern registration bug

Fixes missing method call
This commit is contained in:
Maximilian Kratz 2022-08-30 09:28:30 +02:00
parent 165b654097
commit 277e0f8b0a
9 changed files with 203 additions and 0 deletions

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gips.sort.patternreg</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

View file

@ -0,0 +1,18 @@
Manifest-Version: 1.0
Automatic-Module-Name: gips.sort.patternreg
Bundle-ManifestVersion: 2
Bundle-Name: gips.sort.patternreg
Bundle-Vendor: My Company
Bundle-Version: 1.0.0.qualifier
Bundle-SymbolicName: gips.sort.patternreg; singleton:=true
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-16
Require-Bundle: org.emoflon.ibex.common,
org.emoflon.ibex.gt,
org.emoflon.gips.core,
org.emoflon.ibex.gt.democles,
org.emoflon.ibex.gt.hipe,
test.suite.utils;bundle-version="1.0.0"
Import-Package: listmodel,
listmodel.impl
Export-Package: gips.sort.patternreg.connector

View file

@ -0,0 +1,5 @@
source.. = src/,\
src-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,22 @@
package gips.sort.patternreg.connector;
import org.emoflon.gips.core.ilp.ILPSolverOutput;
import gips.sort.patternreg.api.gips.PatternregGipsAPI;
import test.suite.gips.utils.AConnector;
import test.suite.gips.utils.GipsTestUtils;
public class SortPatternRegConnector extends AConnector {
public SortPatternRegConnector(final String modelPath) {
api = new PatternregGipsAPI();
api.init(GipsTestUtils.pathToAbsUri(modelPath));
}
@Override
public ILPSolverOutput run(final String outputPath) {
solve();
return null;
}
}

View file

@ -0,0 +1,31 @@
import "platform:/resource/gips.sort.listmodel/model/Listmodel.ecore"
config {
solver := GLPK [home:="fu", license:="bar"];
launchConfig := true [main := "TODO"];
timeLimit := true [value := 42.0];
randomSeed := true [value := 73];
presolve := true;
debugOutput := true;
}
rule findFirst {
root: Root {
-entries -> val
}
val: Entry {
.^value := -1
}
}
// Mapping removed on purpose to trigger exception
//mapping eFirst with findFirst;
constraint -> class::Entry {
patterns.findFirst->filter(m | m.nodes().val == self)->count() == 0
}
// TODO: Test this one
//constraint -> class::Entry {
// patterns.findFirst->filter(m | m.nodes().val == self)->notEmpty()
//}

View file

@ -15,6 +15,7 @@ Require-Bundle: org.junit.jupiter.api;bundle-version="5.8.1",
gips.sort;bundle-version="1.0.0",
gips.sort.listmodel;bundle-version="0.0.1"
Import-Package: gips.all.build.objective.connector,
gips.sort.patternreg.connector,
gipsl.all.build.and.connector,
gipsl.all.build.implication.connector,
gipsl.all.build.objective.max.connector,

View file

@ -0,0 +1,84 @@
package test.suite.gips.sort;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.emoflon.smartemf.persistence.SmartEMFResourceFactoryImpl;
import org.junit.jupiter.api.Test;
import gips.sort.patternreg.connector.SortPatternRegConnector;
import listmodel.Entry;
import listmodel.ListmodelFactory;
import listmodel.Root;
import test.suite.gips.utils.AConnector;
public class GipsSortPatternRegSmokeTest {
protected final static String MODEL_PATH = "model.xmi";
protected final static String OUTPUT_PATH = "output.xmi";
protected AConnector con;
private Root root = ListmodelFactory.eINSTANCE.createRoot();
public void genEntry(final int value, final int id) {
final Entry entry = ListmodelFactory.eINSTANCE.createEntry();
entry.setValue(value);
root.getEntries().add(entry);
}
public Root loadModel(final String path) {
// Workaround: Always use absolute path
final URI absPath = URI.createFileURI(System.getProperty("user.dir") + "/" + path);
final ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new SmartEMFResourceFactoryImpl(null));
// ^null is okay if all paths are absolute
final Resource res = rs.getResource(absPath, true);
root = (Root) res.getContents().get(0);
return root;
}
public void persistModel(final String path) {
// Workaround: Always use absolute path
final URI absPath = URI.createFileURI(System.getProperty("user.dir") + "/" + path);
// Create new model for saving
final ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new SmartEMFResourceFactoryImpl(null));
// ^null is okay if all paths are absolute
final Resource r = rs.createResource(absPath);
// Fetch model contents from eMoflon
r.getContents().add(root);
try {
r.save(null);
} catch (final IOException e) {
e.printStackTrace();
}
}
public void callableSetUp() {
persistModel(MODEL_PATH);
con = new SortPatternRegConnector(MODEL_PATH);
}
@Test
public void test10EntriesNormal() {
genNEntries(10);
callableSetUp();
con.run(OUTPUT_PATH);
}
// Utility methods
private void genNEntries(final int n) {
int idCntr = 1;
for (int i = 1; i <= n; i++) {
genEntry(i, idCntr++);
}
}
}