2015-10-17 19:04:32 +02:00
|
|
|
package unify;
|
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
import junit.framework.Assert;
|
|
|
|
|
2015-10-17 19:04:32 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
|
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
2015-10-18 12:51:07 +02:00
|
|
|
import de.dhbwstuttgart.typeinference.Menge;
|
2015-10-17 19:04:32 +02:00
|
|
|
import de.dhbwstuttgart.typeinference.Pair;
|
2015-10-18 15:13:28 +02:00
|
|
|
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
|
2015-10-18 12:51:07 +02:00
|
|
|
import de.dhbwstuttgart.typeinference.unify.Unify;
|
2015-10-17 19:04:32 +02:00
|
|
|
|
|
|
|
public class UnifyTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void unifyTestSimpleTypes() {
|
2015-10-18 15:13:28 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void unifyTestInheritance() {
|
2015-10-18 12:51:07 +02:00
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
// Init Factories and Builders
|
|
|
|
UnifyTypeFactory typeFactory = new UnifyTypeFactory();
|
|
|
|
Unify_FC_TTO_Builder fcBuilder = new Unify_FC_TTO_Builder();
|
|
|
|
UnifyPairMengenBuilder assumptionBuilder = new UnifyPairMengenBuilder();
|
|
|
|
UnifyPairMengenBuilder resultBuilder = new UnifyPairMengenBuilder();
|
2015-10-18 12:51:07 +02:00
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
// Init Types
|
|
|
|
RefType tBool = typeFactory.GetSimpleType("java.lang.Boolean");
|
|
|
|
RefType tString = typeFactory.GetSimpleType("java.lang.String");
|
|
|
|
RefType tInt = typeFactory.GetSimpleType("java.lang.Integer");
|
|
|
|
TypePlaceholder tphA = typeFactory.GetTypePlaceholder("a");
|
2015-10-18 12:51:07 +02:00
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
// Build inheritance hierachy
|
|
|
|
// Bool <. String <. Int
|
|
|
|
fcBuilder.AddInheritance(tBool, tString);
|
|
|
|
fcBuilder.AddInheritance(tString, tInt);
|
2015-10-18 12:51:07 +02:00
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
// Build Assumptions
|
|
|
|
assumptionBuilder.addPair(tphA, tString);
|
2015-10-18 12:51:07 +02:00
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
// Build expected result
|
|
|
|
resultBuilder.addPair(tphA, tBool, PairOperator.Equal);
|
|
|
|
resultBuilder.addPair(tphA, typeFactory.GetExtendsType(tBool), PairOperator.Equal);
|
|
|
|
resultBuilder.addPair(tphA, tString, PairOperator.Equal);
|
|
|
|
resultBuilder.addPair(tphA, typeFactory.GetExtendsType(tString), PairOperator.Equal);
|
2015-10-18 12:51:07 +02:00
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
// Assert
|
|
|
|
Menge<Menge<Pair>> actualResult = Unify.unify(assumptionBuilder.getPairMenge(), fcBuilder.Get_FC_TTO());
|
2015-10-18 12:51:07 +02:00
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
System.out.println(actualResult);
|
|
|
|
System.out.println("-------------------");
|
|
|
|
System.out.println(resultBuilder.getNestedPairMenge());
|
2015-10-18 12:51:07 +02:00
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
Assert.assertTrue(mengeEquals(resultBuilder.getNestedPairMenge(), actualResult));
|
2015-10-17 19:04:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2015-10-18 15:13:28 +02:00
|
|
|
public void unifyTestWildcards() {
|
2015-10-17 19:04:32 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-18 15:13:28 +02:00
|
|
|
protected boolean mengeEquals(Menge<Menge<Pair>> m1, Menge<Menge<Pair>> m2) {
|
|
|
|
return m1.containsAll(m2) && m2.containsAll(m1);
|
2015-10-17 19:04:32 +02:00
|
|
|
}
|
|
|
|
}
|