Tests anpassen. Beginnen mit Oder Constraints
This commit is contained in:
parent
e7e96d5943
commit
277dac20e7
@ -49,7 +49,6 @@ public class Clingo {
|
||||
InputStream output = clingo.getInputStream();
|
||||
clingo.waitFor();
|
||||
String result = IOUtils.toString(output, StandardCharsets.UTF_8);
|
||||
System.out.println(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
import javax.management.Notification;
|
||||
import java.util.*;
|
||||
|
||||
public class ASPFactory implements TypeVisitor<String>{
|
||||
@ -19,16 +20,23 @@ public class ASPFactory implements TypeVisitor<String>{
|
||||
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException{
|
||||
ASPFactory factory = new ASPFactory();
|
||||
factory.convertFC(fcClasses);
|
||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
for(Constraint<Pair> constraint : constraints1){
|
||||
for(Pair p : constraint){
|
||||
factory.convertPair(p);
|
||||
//List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
for(Pair p : constraints.getUndConstraints()){
|
||||
factory.convertPair(p);
|
||||
}
|
||||
for(Set<Constraint<Pair>> constraint : constraints.getOderConstraints()){
|
||||
for(Constraint<Pair> oder : constraint){
|
||||
factory.convertOderConstraint(oder);
|
||||
}
|
||||
}
|
||||
|
||||
return factory.writer.getASPFile();
|
||||
}
|
||||
|
||||
private void convertOderConstraint(Constraint<Pair> oder) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ASPWriter writer = new ASPWriter();
|
||||
boolean isFCType = false;
|
||||
|
||||
|
@ -52,4 +52,12 @@ public class ConstraintSet<A> {
|
||||
ret.oderConstraints = newOder;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Constraint<A> getUndConstraints() {
|
||||
return undConstraints;
|
||||
}
|
||||
|
||||
public List<Set<Constraint<A>>> getOderConstraints() {
|
||||
return oderConstraints;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
@ -19,7 +19,6 @@ import org.junit.Test;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Ref;
|
||||
import java.util.*;
|
||||
|
||||
public class UnifyWithoutWildcards {
|
||||
@ -34,7 +33,7 @@ public class UnifyWithoutWildcards {
|
||||
RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), list1, new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
|
||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
ResultSet resultSet = run(testSet);
|
||||
ResultSet resultSet = run(testSet, getFC());
|
||||
//System.out.println(ResultSetPrinter.print(resultSet));
|
||||
assert resultSet.results.size() > 0;
|
||||
ResolvedType rsType = resultSet.resolveType(list2.get(1));
|
||||
@ -48,7 +47,7 @@ public class UnifyWithoutWildcards {
|
||||
RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test1"), list1, new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken());
|
||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
ResultSet resultSet = run(testSet);
|
||||
ResultSet resultSet = run(testSet, getFC());
|
||||
//System.out.println(ResultSetPrinter.print(resultSet));
|
||||
assert resultSet.results.size() == 0; //Hier gibt es keine Lösung.
|
||||
//TODO: Kann in zukünfigen Fällen eine Lösung geben
|
||||
@ -60,19 +59,55 @@ public class UnifyWithoutWildcards {
|
||||
TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken());
|
||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
ResultSet resultSet = run(testSet);
|
||||
ResultSet resultSet = run(testSet, getFC());
|
||||
System.out.println(resultSet.results.size());
|
||||
}
|
||||
|
||||
public ResultSet run(ConstraintSet<Pair> toTest) throws IOException, InterruptedException, ClassNotFoundException {
|
||||
@Test
|
||||
public void failTest() throws InterruptedException, IOException, ClassNotFoundException {
|
||||
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||
TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken());
|
||||
RefType t3 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test2"), new ArrayList<>(), new NullToken());
|
||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
testSet.addUndConstraint(new Pair(t1, t3, PairOperator.SMALLERDOT));
|
||||
Set<ClassOrInterface> fc = new HashSet<>();
|
||||
fc.add(ASTFactory.createClass(Test2.class));
|
||||
ResultSet resultSet = run(testSet, fc);
|
||||
assert resultSet.results.size()==1;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oderConstraints() throws InterruptedException, IOException, ClassNotFoundException {
|
||||
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||
for(int i = 0; i<1; i++){
|
||||
TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken());
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||
RefType t3 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test1"), list1, new NullToken());
|
||||
Set<Constraint<Pair>> oderCons = new HashSet<>();
|
||||
Constraint<Pair> cons1 = new Constraint<>();
|
||||
cons1.add(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
oderCons.add(cons1);
|
||||
Constraint<Pair> cons2 = new Constraint<>();
|
||||
cons2.add(new Pair(t1, t3, PairOperator.SMALLERDOT));
|
||||
oderCons.add(cons2);
|
||||
testSet.addOderConstraint(oderCons);
|
||||
}
|
||||
ResultSet resultSet = run(testSet, getFC());
|
||||
System.out.println(resultSet.results.size());
|
||||
}
|
||||
|
||||
public ResultSet run(ConstraintSet<Pair> toTest, Collection<ClassOrInterface> fc) throws IOException, InterruptedException, ClassNotFoundException {
|
||||
String content = "";
|
||||
content = ASPFactory.generateASP(toTest, this.getFC());
|
||||
content = ASPFactory.generateASP(toTest, fc);
|
||||
|
||||
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
|
||||
writer.println(content);
|
||||
writer.close();
|
||||
Clingo clingo = new Clingo(Arrays.asList(new File(tempDirectory + "test.lp")));
|
||||
String result = clingo.runClingo();
|
||||
System.out.println(result);
|
||||
ResultSet resultSet = ASPParser.parse(result, getInvolvedTPHS(toTest));
|
||||
return resultSet;
|
||||
}
|
||||
@ -129,4 +164,6 @@ public class UnifyWithoutWildcards {
|
||||
private class Matrix<A> extends HashMap<A,Map<Integer, A>>{}
|
||||
|
||||
private class Test1<A> extends Object{}
|
||||
|
||||
private class Test2 extends Object{}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user