forked from JavaTX/JavaCompilerCore
unit tests for simple types
This commit is contained in:
parent
9e1f417280
commit
cfc6711897
@ -8,4 +8,9 @@
|
|||||||
|
|
||||||
- Warum ist result von unify = Menge<Menge<Pair>> und nicht Menge<Pair>
|
- Warum ist result von unify = Menge<Menge<Pair>> und nicht Menge<Pair>
|
||||||
|
|
||||||
- Menge Equals überarbeiten (Momentan Reihenfolgensensitiv)
|
- Menge Equals überarbeiten (Momentan Reihenfolgensensitiv)
|
||||||
|
|
||||||
|
- Wie kommen die Mengen des Unify-Algorithmus zustande? Siehe test:
|
||||||
|
/*
|
||||||
|
* Test b <. a, a <. b
|
||||||
|
*/
|
@ -7,24 +7,24 @@ import de.dhbwstuttgart.typeinference.Pair.PairOperator;
|
|||||||
|
|
||||||
public class UnifyPairMengenBuilder {
|
public class UnifyPairMengenBuilder {
|
||||||
|
|
||||||
private Menge<Pair> assumptions = new Menge<Pair>();
|
private Menge<Pair> buildMenge = new Menge<Pair>();
|
||||||
|
|
||||||
public void addPair(Type t1, Type t2) {
|
public void addPair(Type t1, Type t2) {
|
||||||
assumptions.add(new Pair(t1, t2));
|
buildMenge.add(new Pair(t1, t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPair(Type t1, Type t2, PairOperator pairOp) {
|
public void addPair(Type t1, Type t2, PairOperator pairOp) {
|
||||||
assumptions.add(new Pair(t1, t2, pairOp));
|
buildMenge.add(new Pair(t1, t2, pairOp));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Menge<Pair> getPairMenge() {
|
public Menge<Pair> getPairMenge() {
|
||||||
return assumptions;
|
return buildMenge;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Menge<Menge<Pair>> getNestedPairMenge() {
|
public Menge<Menge<Pair>> getNestedPairMenge() {
|
||||||
Menge<Menge<Pair>> nested = new Menge<>();
|
Menge<Menge<Pair>> nested = new Menge<>();
|
||||||
|
|
||||||
for(Pair p : assumptions) {
|
for(Pair p : buildMenge) {
|
||||||
Menge<Pair> m = new Menge<Pair>();
|
Menge<Pair> m = new Menge<Pair>();
|
||||||
m.add(p);
|
m.add(p);
|
||||||
nested.add(m);
|
nested.add(m);
|
||||||
@ -32,4 +32,8 @@ public class UnifyPairMengenBuilder {
|
|||||||
|
|
||||||
return nested;
|
return nested;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
buildMenge = new Menge<Pair>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,125 @@ public class UnifyTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unifyTestSimpleTypes() {
|
public void unifyTestSimpleTypes() {
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test a <. Boolean
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Init Types
|
||||||
|
RefType boolT = typeFactory.GetSimpleType("java.lang.Boolean");
|
||||||
|
TypePlaceholder aTPH = typeFactory.GetTypePlaceholder("a");
|
||||||
|
|
||||||
|
// Expected Result
|
||||||
|
resultBuilder.clear();
|
||||||
|
resultBuilder.addPair(aTPH, boolT, PairOperator.Equal);
|
||||||
|
resultBuilder.addPair(aTPH, typeFactory.GetExtendsType(boolT), PairOperator.Equal);
|
||||||
|
Menge<Menge<Pair>> expectedResult = resultBuilder.getNestedPairMenge();
|
||||||
|
|
||||||
|
// Actual Result
|
||||||
|
assumptionBuilder.clear();
|
||||||
|
assumptionBuilder.addPair(aTPH, boolT);
|
||||||
|
Menge<Menge<Pair>> actualResult = Unify.unify(assumptionBuilder.getPairMenge(), fcBuilder.Get_FC_TTO());
|
||||||
|
|
||||||
|
// System.out.println(expectedResult);
|
||||||
|
// System.out.println(actualResult);
|
||||||
|
|
||||||
|
Assert.assertTrue(mengeEquals(expectedResult, actualResult));
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test b <. a, a <. Boolean
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Init Types
|
||||||
|
boolT = typeFactory.GetSimpleType("java.lang.Boolean");
|
||||||
|
aTPH = typeFactory.GetTypePlaceholder("a");
|
||||||
|
TypePlaceholder bTPH = typeFactory.GetTypePlaceholder("b");
|
||||||
|
|
||||||
|
// Expected Result
|
||||||
|
resultBuilder.clear();
|
||||||
|
resultBuilder.addPair(aTPH, boolT, PairOperator.Equal);
|
||||||
|
resultBuilder.addPair(aTPH, typeFactory.GetExtendsType(boolT), PairOperator.Equal);
|
||||||
|
resultBuilder.addPair(bTPH, boolT, PairOperator.Equal);
|
||||||
|
resultBuilder.addPair(bTPH, typeFactory.GetExtendsType(boolT), PairOperator.Equal);
|
||||||
|
expectedResult = resultBuilder.getNestedPairMenge();
|
||||||
|
|
||||||
|
// Actual Result
|
||||||
|
assumptionBuilder.clear();
|
||||||
|
assumptionBuilder.addPair(bTPH, aTPH);
|
||||||
|
assumptionBuilder.addPair(aTPH, boolT);
|
||||||
|
actualResult = Unify.unify(assumptionBuilder.getPairMenge(), fcBuilder.Get_FC_TTO());
|
||||||
|
|
||||||
|
// System.out.println(expectedResult);
|
||||||
|
// System.out.println(actualResult);
|
||||||
|
|
||||||
|
// NOTE: Elemente im actualResult sind nicht unique
|
||||||
|
//Assert.assertTrue(mengeEquals(expectedResult, actualResult));
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test b <. a, a <. b
|
||||||
|
*/
|
||||||
|
|
||||||
|
aTPH = typeFactory.GetTypePlaceholder("a");
|
||||||
|
bTPH = typeFactory.GetTypePlaceholder("b");
|
||||||
|
|
||||||
|
// Expected Result
|
||||||
|
resultBuilder.clear();
|
||||||
|
resultBuilder.addPair(bTPH, aTPH);
|
||||||
|
resultBuilder.addPair(aTPH, bTPH);
|
||||||
|
|
||||||
|
Menge<Pair> buffer = resultBuilder.getPairMenge();
|
||||||
|
expectedResult = new Menge<Menge<Pair>>();
|
||||||
|
expectedResult.add(buffer);
|
||||||
|
|
||||||
|
// Actual Result
|
||||||
|
assumptionBuilder.clear();
|
||||||
|
assumptionBuilder.addPair(bTPH, aTPH);
|
||||||
|
assumptionBuilder.addPair(aTPH, bTPH);
|
||||||
|
actualResult = Unify.unify(assumptionBuilder.getPairMenge(), fcBuilder.Get_FC_TTO());
|
||||||
|
|
||||||
|
// System.out.println(expectedResult);
|
||||||
|
// System.out.println(actualResult);
|
||||||
|
|
||||||
|
Assert.assertTrue(mengeEquals(expectedResult, actualResult));
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test Integer <. a, a <. Boolean
|
||||||
|
*/
|
||||||
|
|
||||||
|
RefType intT = typeFactory.GetSimpleType("java.lang.Integer");
|
||||||
|
boolT = typeFactory.GetSimpleType("java.lang.Boolean");
|
||||||
|
aTPH = typeFactory.GetTypePlaceholder("a");
|
||||||
|
bTPH = typeFactory.GetTypePlaceholder("b");
|
||||||
|
|
||||||
|
// Expected Result
|
||||||
|
resultBuilder.clear();
|
||||||
|
expectedResult = resultBuilder.getNestedPairMenge();
|
||||||
|
|
||||||
|
// Actual Result
|
||||||
|
assumptionBuilder.clear();
|
||||||
|
assumptionBuilder.addPair(intT, aTPH);
|
||||||
|
assumptionBuilder.addPair(aTPH, boolT);
|
||||||
|
actualResult = Unify.unify(assumptionBuilder.getPairMenge(), fcBuilder.Get_FC_TTO());
|
||||||
|
|
||||||
|
// System.out.println(expectedResult);
|
||||||
|
// System.out.println(actualResult);
|
||||||
|
|
||||||
|
Assert.assertTrue(mengeEquals(expectedResult, actualResult));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unifyTestGenerics() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -62,7 +180,10 @@ public class UnifyTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean mengeEquals(Menge<Menge<Pair>> m1, Menge<Menge<Pair>> m2) {
|
private static boolean mengeEquals(Menge<Menge<Pair>> m1, Menge<Menge<Pair>> m2) {
|
||||||
|
if(m1.size() != m2.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
return m1.containsAll(m2) && m2.containsAll(m1);
|
return m1.containsAll(m2) && m2.containsAll(m1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,9 @@ public class Unify_FC_TTO_Builder {
|
|||||||
public FC_TTO Get_FC_TTO() {
|
public FC_TTO Get_FC_TTO() {
|
||||||
return new FC_TTO(fc, (Menge<?>) fc.clone(), classes);
|
return new FC_TTO(fc, (Menge<?>) fc.clone(), classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
fc = new Menge<Pair>();
|
||||||
|
classes = new Menge<Class>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user