From bb4eaaccc526558e830eb76730608a157752f372 Mon Sep 17 00:00:00 2001 From: NoName11234 <47484268+NoName11234@users.noreply.github.com> Date: Thu, 18 Jan 2024 18:29:36 +0100 Subject: [PATCH] implemented unify test --- src/test/java/typeinference/UnifyTest.java | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/test/java/typeinference/UnifyTest.java b/src/test/java/typeinference/UnifyTest.java index 157556983..d52fc9b26 100644 --- a/src/test/java/typeinference/UnifyTest.java +++ b/src/test/java/typeinference/UnifyTest.java @@ -1,17 +1,27 @@ package typeinference; +import com.google.common.base.Optional; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.parser.scope.JavaClassName; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.Constructor; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; 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; @@ -40,11 +50,11 @@ public class UnifyTest { UnifyPair pair2 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT); type1 = new ReferenceType("String"); - type2 = new ReferenceType("b"); + type2 = new PlaceholderType("b"); UnifyPair pair3 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT); type1 = new ReferenceType("Integer"); - type2 = new ReferenceType("c"); + type2 = new PlaceholderType("c"); UnifyPair pair4 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT); Set undConstraints = new HashSet<>(); @@ -53,10 +63,32 @@ public class UnifyTest { undConstraints.add(pair3); undConstraints.add(pair4); - /*IFiniteClosure finiteClosure = UnifyTypeFactory. + List>> oderConstraints = new ArrayList<>(); + + Set constraints = new HashSet<>(); + type1 = new ReferenceType("Object"); + type2 = new ReferenceType("String"); + constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); + type1 = new ReferenceType("Number"); + type2 = new ReferenceType("Integer"); + constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); + type1 = new ReferenceType("Object"); + type2 = new ReferenceType("Number"); + constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); + type1 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X"))); + type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X"))); + constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); + type1 = new ReferenceType("Object"); + type2 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X"))); + constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); + + IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter()); TypeUnify unifyAlgo = new TypeUnify(); - unifyAlgo.unifyParallel()*/ + ConstraintSet< Pair> cons = new ConstraintSet<>(); + UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure); + UnifyTaskModel tasks = new UnifyTaskModel(); + urm = unifyAlgo.unifyParallel(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks); } /* @Test