2015-11-09 13:39:26 +00:00
|
|
|
package unify;
|
|
|
|
|
2016-03-14 13:46:10 +00:00
|
|
|
import java.util.ArrayList;
|
2015-11-23 00:03:01 +00:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
2015-12-26 23:29:23 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.unify.model.MPair;
|
|
|
|
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
|
2016-03-14 13:46:10 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.unify.model.Type;
|
|
|
|
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
2016-03-16 13:56:02 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.unifynew.TypeFactory;
|
2015-11-09 13:39:26 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.unifynew.Unify;
|
|
|
|
|
|
|
|
public class UnifyTest extends Unify {
|
2015-11-23 00:03:01 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void unifyTest() {
|
|
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
|
|
|
Set<MPair> eq = new HashSet<MPair>();
|
|
|
|
|
2015-12-26 15:22:35 +00:00
|
|
|
//fcb.add(tf.getSimpleType("Number"), tf.getSimpleType("Object"));
|
2015-11-23 00:03:01 +00:00
|
|
|
fcb.add(tf.getSimpleType("Integer"), tf.getSimpleType("Number"));
|
|
|
|
fcb.add(tf.getSimpleType("Double"), tf.getSimpleType("Number"));
|
2016-03-20 14:09:12 +00:00
|
|
|
fcb.add(tf.getSimpleType("MyList"), tf.getSimpleType("List", tf.getSimpleType("Integer")));
|
2016-03-14 13:46:10 +00:00
|
|
|
//fcb.add(tf.getSimpleType("List", "T"));
|
2015-11-23 00:03:01 +00:00
|
|
|
|
|
|
|
IFiniteClosure fc = fcb.getCollectionExample();
|
|
|
|
|
|
|
|
// Vector<Integer> <. Vector<A>
|
2015-11-27 18:52:59 +00:00
|
|
|
// Vector<Integer <. Vector<C>
|
2015-12-26 15:22:35 +00:00
|
|
|
// A <. Integer
|
2015-12-27 14:01:59 +00:00
|
|
|
// Number <. A
|
2015-11-23 00:03:01 +00:00
|
|
|
// Double <. B
|
|
|
|
// B <. Object
|
2016-03-20 17:05:34 +00:00
|
|
|
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));
|
2015-12-27 14:01:59 +00:00
|
|
|
//eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "C"), PairOperator.SMALLERDOT));
|
2016-03-20 17:05:34 +00:00
|
|
|
//eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("List", "A"), PairOperator.SMALLERDOT));
|
2016-03-13 15:00:00 +00:00
|
|
|
//eq.add(new MPair(tf.getSimpleType("Number"), tf.getPlaceholderType("A"), PairOperator.SMALLERDOT));
|
2015-11-27 18:52:59 +00:00
|
|
|
//eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT));
|
2015-12-27 14:01:59 +00:00
|
|
|
//eq.add(new MPair(tf.getSimpleType("Double"), tf.getPlaceholderType("B"), PairOperator.SMALLERDOT));
|
2015-12-26 15:22:35 +00:00
|
|
|
//eq.add(new MPair(tf.getPlaceholderType("B"), tf.getSimpleType("Object"), PairOperator.EQUALSDOT));
|
2015-11-23 00:03:01 +00:00
|
|
|
|
2015-12-26 17:49:11 +00:00
|
|
|
System.out.println(this.unify(eq, fc));
|
2015-11-23 00:03:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void applyTypeUnificationRulesTest() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void calculatePairSetsTest() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-14 13:46:10 +00:00
|
|
|
@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);
|
|
|
|
|
2016-03-20 14:09:12 +00:00
|
|
|
Set<TypeParams> result = permuteParams(candidates);
|
2016-03-14 13:46:10 +00:00
|
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
}
|
|
|
|
|
2015-11-09 13:39:26 +00:00
|
|
|
}
|