forked from JavaTX/JavaCompilerCore
90 lines
3.1 KiB
Java
90 lines
3.1 KiB
Java
package unify;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
import org.junit.Test;
|
|
|
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
|
import de.dhbwstuttgart.typeinference.unify.model.MPair;
|
|
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
|
|
import de.dhbwstuttgart.typeinference.unify.model.Type;
|
|
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
|
import de.dhbwstuttgart.typeinference.unifynew.TypeFactory;
|
|
import de.dhbwstuttgart.typeinference.unifynew.Unify;
|
|
|
|
public class UnifyTest extends Unify {
|
|
|
|
@Test
|
|
public void unifyTest() {
|
|
TypeFactory tf = new TypeFactory();
|
|
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
|
Set<MPair> eq = new HashSet<MPair>();
|
|
|
|
//fcb.add(tf.getSimpleType("Number"), tf.getSimpleType("Object"));
|
|
fcb.add(tf.getSimpleType("Integer"), tf.getSimpleType("Number"));
|
|
fcb.add(tf.getSimpleType("Double"), tf.getSimpleType("Number"));
|
|
fcb.add(tf.getSimpleType("MyList"), tf.getSimpleType("List", tf.getSimpleType("Integer")));
|
|
//fcb.add(tf.getSimpleType("List", "T"));
|
|
|
|
IFiniteClosure fc = fcb.getCollectionExample();
|
|
|
|
// Vector<Integer> <. Vector<A>
|
|
// Vector<Integer <. Vector<C>
|
|
// A <. Integer
|
|
// Number <. A
|
|
// Double <. B
|
|
// B <. Object
|
|
eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT));
|
|
eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Number")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT));
|
|
//eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "C"), PairOperator.SMALLERDOT));
|
|
//eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("List", "A"), PairOperator.SMALLERDOT));
|
|
//eq.add(new MPair(tf.getSimpleType("Number"), tf.getPlaceholderType("A"), PairOperator.SMALLERDOT));
|
|
//eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT));
|
|
//eq.add(new MPair(tf.getSimpleType("Double"), tf.getPlaceholderType("B"), PairOperator.SMALLERDOT));
|
|
//eq.add(new MPair(tf.getPlaceholderType("B"), tf.getSimpleType("Object"), PairOperator.EQUALSDOT));
|
|
|
|
System.out.println(this.unify(eq, fc));
|
|
|
|
}
|
|
|
|
@Test
|
|
public void applyTypeUnificationRulesTest() {
|
|
|
|
}
|
|
|
|
@Test
|
|
public void calculatePairSetsTest() {
|
|
|
|
}
|
|
|
|
@Test
|
|
public void permuteParamsTest() {
|
|
TypeFactory tf = new TypeFactory();
|
|
ArrayList<Set<Type>> candidates = new ArrayList<>();
|
|
|
|
Set<Type> p1 = new HashSet<>();
|
|
p1.add(tf.getPlaceholderType("p11"));
|
|
p1.add(tf.getExtendsType(tf.getSimpleType("p12")));
|
|
p1.add(tf.getSimpleType("p13"));
|
|
|
|
Set<Type> p2 = new HashSet<>();
|
|
p2.add(tf.getPlaceholderType("p21"));
|
|
p2.add(tf.getPlaceholderType("p22"));
|
|
|
|
Set<Type> p3 = new HashSet<>();
|
|
p3.add(tf.getSimpleType("p31", "T"));
|
|
p3.add(tf.getSimpleType("p32"));
|
|
|
|
candidates.add(p1);
|
|
candidates.add(p2);
|
|
candidates.add(p3);
|
|
|
|
Set<TypeParams> result = permuteParams(candidates);
|
|
|
|
System.out.println(result);
|
|
}
|
|
|
|
}
|