forked from JavaTX/JavaCompilerCore
UnifyTestSubclasses anfügen
This commit is contained in:
parent
377987abda
commit
03b1321a45
@ -267,6 +267,28 @@ public class UnifyTest extends Unify {
|
||||
actual = unify(eq, fc);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
|
||||
/*
|
||||
* Test 12:
|
||||
*
|
||||
* (void <. void)
|
||||
*/
|
||||
|
||||
eq = new HashSet<>();
|
||||
eq.add(new UnifyPair(tphA, tf.getSimpleType("void"), PairOperator.SMALLERDOT));
|
||||
eq.add(new UnifyPair(tf.getSimpleType("void"), tphA, PairOperator.SMALLERDOT));
|
||||
|
||||
expected = new HashSet<>();
|
||||
addAsSet(expected, new UnifyPair(tphA, tf.getSimpleType("void"), PairOperator.EQUALSDOT));
|
||||
|
||||
//Test funktioniert momentan auch ohne ein "void" in der Finite Closure
|
||||
//fcb.add(tf.getSimpleType("void"), tf.getSimpleType("Object"));
|
||||
|
||||
IFiniteClosure voidFC = fcb.getFiniteClosure();
|
||||
|
||||
actual = unify(eq, voidFC);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -590,6 +612,55 @@ public class UnifyTest extends Unify {
|
||||
|
||||
System.out.println("Test Matrix:");
|
||||
System.out.println(actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unifyTestSubclasses() {
|
||||
/*
|
||||
* TPH1 < Integer
|
||||
* Integer < Integer
|
||||
* TPH1 < TPH2
|
||||
* TPH2 < Integer
|
||||
*
|
||||
* Einzige korrekte Lösung:
|
||||
* TPH1 = Integer, TPH2 = Integer
|
||||
*/
|
||||
TypeFactory tf = new TypeFactory();
|
||||
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
||||
|
||||
UnifyType tphT1 = tf.getPlaceholderType("T1");
|
||||
UnifyType tphT2 = tf.getPlaceholderType("T2");
|
||||
UnifyType tphT3 = tf.getPlaceholderType("T3");
|
||||
|
||||
UnifyType integer = tf.getSimpleType("java.lang.Integer");
|
||||
UnifyType bool = tf.getSimpleType("java.lang.Boolean");
|
||||
UnifyType object = tf.getSimpleType("java.lang.Object");
|
||||
UnifyType main = tf.getSimpleType("Main");
|
||||
|
||||
fcb.add(integer, object);
|
||||
fcb.add(main, object);
|
||||
fcb.add(bool, object);
|
||||
|
||||
IFiniteClosure fc = fcb.getFiniteClosure();
|
||||
|
||||
Set<UnifyPair> eq = new HashSet<UnifyPair>();
|
||||
eq.add(new UnifyPair(tphT1, integer, PairOperator.SMALLERDOT));
|
||||
eq.add(new UnifyPair(integer, integer, PairOperator.SMALLERDOT));
|
||||
eq.add(new UnifyPair(tphT1, tphT2, PairOperator.SMALLERDOT));
|
||||
eq.add(new UnifyPair(tphT2, integer, PairOperator.SMALLERDOT));
|
||||
|
||||
Set<Set<UnifyPair>> expected = new HashSet<>();
|
||||
Set<UnifyPair> solution = new HashSet<UnifyPair>();
|
||||
solution.add(new UnifyPair(tphT1, integer, PairOperator.EQUALSDOT));
|
||||
solution.add(new UnifyPair(tphT2, integer, PairOperator.EQUALSDOT));
|
||||
expected.add(solution);
|
||||
|
||||
Set<Set<UnifyPair>> actual = unify(eq, fc);
|
||||
|
||||
System.out.println("Test Subclass:");
|
||||
System.out.println(actual);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user