From 46eb7b12e61f625a13222d6252afffbefcae8e95 Mon Sep 17 00:00:00 2001 From: NoName11234 <47484268+NoName11234@users.noreply.github.com> Date: Fri, 10 May 2024 20:25:11 +0200 Subject: [PATCH] added matrix test --- src/test/java/UnifyTest.java | 122 ++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/src/test/java/UnifyTest.java b/src/test/java/UnifyTest.java index 1be6eb7..ddf5ef2 100644 --- a/src/test/java/UnifyTest.java +++ b/src/test/java/UnifyTest.java @@ -81,5 +81,125 @@ 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 PlaceholderType("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<>(); + UnifyResultModelParallel urm = new UnifyResultModelParallel(cons, finiteClosure); + UnifyTaskModelParallel tasks = new UnifyTaskModelParallel(); + Set> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks); + System.out.println(solution); + System.out.println(solution.size()); + } +}