diff --git a/src/test/java/typeinference/UnifyTest.java b/src/test/java/typeinference/UnifyTest.java index 366b010ec..f79100f10 100644 --- a/src/test/java/typeinference/UnifyTest.java +++ b/src/test/java/typeinference/UnifyTest.java @@ -7,7 +7,16 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; +import de.dhbwstuttgart.typeinference.unify.UnifyTaskModel; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.*; +import org.apache.commons.io.output.NullWriter; import org.junit.Test; import java.io.File; @@ -24,7 +33,71 @@ import java.util.Set; public class UnifyTest { public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/"; -/* + + private UnifyPair genPairListOfInteger(String name){ + + UnifyType type1 = new PlaceholderType(name); + UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("Integer"))); + UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT); + + return pair1; + } + private UnifyPair genPairListOfString(String name){ + + PlaceholderType type1 = new PlaceholderType(name); + UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("String"))); + UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT); + + return pair1; + } + @Test + public void unifyTest(){ + UnifyType type1; + UnifyType type2; + + Set undConstraints = new HashSet<>(); + undConstraints.add(genPairListOfInteger("a")); + undConstraints.add(genPairListOfString("a")); + + undConstraints.add(genPairListOfInteger("b")); + undConstraints.add(genPairListOfString("b")); + undConstraints.add(genPairListOfInteger("c")); + undConstraints.add(genPairListOfString("c")); + undConstraints.add(genPairListOfInteger("d")); + undConstraints.add(genPairListOfString("d")); + undConstraints.add(genPairListOfInteger("e")); + undConstraints.add(genPairListOfString("e")); + undConstraints.add(genPairListOfInteger("e1")); + undConstraints.add(genPairListOfString("e1")); + undConstraints.add(genPairListOfInteger("e2")); + undConstraints.add(genPairListOfString("e2")); + undConstraints.add(genPairListOfInteger("e3")); + undConstraints.add(genPairListOfString("e3")); + + List>> oderConstraints = new ArrayList<>(); + + Set constraints = new HashSet<>(); + type1 = new ReferenceType("Object"); + type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X"))); + constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER)); + type1 = new ReferenceType("Object"); + type2 = new ReferenceType("Integer"); + constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER)); + type1 = new ReferenceType("Object"); + type2 = new ReferenceType("String"); + constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER)); + + IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter()); + + TypeUnify unifyAlgo = new TypeUnify(); + ConstraintSet cons = new ConstraintSet<>(); + UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure); + UnifyTaskModel tasks = new UnifyTaskModel(); + Set> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks); + System.out.println(solution.size()); + System.out.println(solution); + } + /* @Test public void finiteClosure() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"fc.jav"));