forked from i21017/JavaTypeUnify
added matrix test
This commit is contained in:
parent
80c3e5d02c
commit
46eb7b12e6
@ -81,5 +81,125 @@ public class UnifyTest {
|
||||
Set<Set<UnifyPair>> 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<UnifyPair> 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<x?>
|
||||
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<Integer> <. v2
|
||||
type1 = new ReferenceType("Vector", new TypeParams(new ReferenceType("Integer")));
|
||||
type2 = new PlaceholderType("v2");
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//v1 <. Vector<y?>
|
||||
type1 = new PlaceholderType("v1");
|
||||
type2 = new ReferenceType("Vector", new TypeParams(new PlaceholderType("y")));
|
||||
undConstraints.add(new UnifyPair(type1, type2, PairOperator.SMALLERDOT));
|
||||
//m <. Vector<z?>
|
||||
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<z2?>
|
||||
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<y2?>
|
||||
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<x3?>
|
||||
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<x2?>
|
||||
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<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
|
||||
|
||||
//FiniteClosure
|
||||
Set<UnifyPair> constraints = new HashSet<>();
|
||||
//Matrix extends Vector<Vector<Integer>>
|
||||
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<X> 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<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
||||
System.out.println(solution);
|
||||
System.out.println(solution.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user