diff --git a/src/test/java/UnifyTest.java b/src/test/java/UnifyTest.java index 6f75a89..5661c72 100644 --- a/src/test/java/UnifyTest.java +++ b/src/test/java/UnifyTest.java @@ -81,5 +81,126 @@ public class UnifyTest { Set> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks); System.out.println(solution.size()); //System.out.println(solution); - }} + } + + @Test + public void matrixTest(){ + UnifyType type1; + UnifyType type2; + Set undConstraints = new HashSet<>(); + + //und-constraints + //Matrix <. ret + type1 = new ReferenceType("Matrix"); + type2 = new PlaceholderType("ret"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //Integer <. i + type1 = new ReferenceType("Integer"); + type2 = new PlaceholderType("i"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //Matrix <. Vector + type1 = new ReferenceType("Matrix"); + type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("x"))); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //x? <. v1 + type1 = new PlaceholderType("x"); + type2 = new PlaceholderType("v1"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //i <. Integer + type1 = new PlaceholderType("i"); + type2 = new ReferenceType("Integer"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //Vector <. v2 + type1 = new ReferenceType("Vector", new TypeParams(new ReferenceType("Integer"))); + type2 = new PlaceholderType("v2"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //v1 <. Vector + type1 = new PlaceholderType("v1"); + type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("y"))); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //m <. Vector + type1 = new PlaceholderType("m"); + type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("z"))); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //z? <. zr + type1 = new PlaceholderType("z"); + type2 = new PlaceholderType("zr"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //zr <. Vector + type1 = new PlaceholderType("zr"); + type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("z2"))); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //z2? <. z2r + type1 = new PlaceholderType("z2"); + type2 = new PlaceholderType("z2r"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //z2r <. Integer + type1 = new PlaceholderType("z2r"); + type2 = new ReferenceType("Integer"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //v1 <. Vector + type1 = new PlaceholderType("v1"); + type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("y2"))); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //y2? <. y2r + type1 = new PlaceholderType("y2"); + type2 = new PlaceholderType("y2r"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //y2r <. Integer + type1 = new PlaceholderType("y2r"); + type2 = new ReferenceType("Integer"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //v2 <. Vector + type1 = new PlaceholderType("v2"); + type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("x3"))); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //x3? <. x3r + type1 = new PlaceholderType("x3"); + type2 = new PlaceholderType("x3r"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //Integer <. x3r + type1 = new ReferenceType("Integer"); + type2 = new PlaceholderType("x3r"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //ret <. Vector + type1 = new PlaceholderType("ret"); + type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("x2"))); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //x2? <. x2r + type1 = new PlaceholderType("x2"); + type2 = new PlaceholderType("x2r"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + //v2 <. x2r + type1 = new PlaceholderType("v2"); + type2 = new PlaceholderType("x2r"); + undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT)); + + //oder-constraints + List>> oderConstraints = new ArrayList<>(); + + //FiniteClosure + Set constraints = new HashSet<>(); + //Matrix extends Vector> + type1 = new ReferenceType("Matrix"); + type2 = new ReferenceType("Vector", new TypeParams(new ReferenceType("Vector", new TypeParams(new ReferenceType("Integer"))))); + constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); + //Vector extends Object + type1 = new ReferenceType("Vector", new TypeParams(new ReferenceType("X"))); + type2 = new ReferenceType("Object"); + constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); + //Integer extends Object + type1 = new ReferenceType("Integer"); + type2 = new ReferenceType("Object"); + constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); + FiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter()); + + TypeUnify unifyAlgo = new TypeUnify(); + ConstraintSet< Pair> 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); + System.out.println(solution.size()); + } +}