reduce Ext Tests

This commit is contained in:
Florian Steurer 2015-11-08 22:25:23 +01:00
parent eeba9fb734
commit c1e4fce67f

View File

@ -233,34 +233,64 @@ public class RuleSetTest {
@Test @Test
public void testReduceExt() { public void testReduceExt() {
Set<MPair> pairs = new HashSet<MPair>(); TypeFactory tf = new TypeFactory();
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
SimpleType t1 = new SimpleType("t1"); /*
SimpleType t2 = new SimpleType("t2"); * Positive Tests
SimpleType t3 = new SimpleType("t3"); */
SimpleType t4 = new SimpleType("t4");
SimpleType t5 = new SimpleType("t5");
SimpleType t6 = new SimpleType("t6");
SimpleType t7 = new SimpleType("t7");
SimpleType t8 = new SimpleType("t8");
SimpleType t9 = new SimpleType("t9");
SimpleType ta = new SimpleType("a", t1, t2, t3); // X<T1, T2, T3, T4>
SimpleType taa = new SimpleType("a", t4, t5, t6); SimpleType x1 = tf.getSimpleType("X", "T1", "T2", "T3", "T4");
SimpleType tb = new SimpleType("b", t3, t1, t2); // Y<T4, T1, T2, T3>
SimpleType tbb = new SimpleType("b", t7, t8, t9); SimpleType y1 = tf.getSimpleType("Y", "T4", "T1", "T2", "T3");
SimpleType buffer = tf.getSimpleType("Buffer");
//X<Int, ? extends Double, M, N>
SimpleType x2 = tf.getSimpleType("X", tf.getSimpleType("Int"), tf.getExtendsType(tf.getSimpleType("Double")), tf.getPlaceholderType("M"), tf.getPlaceholderType("N"));
//? extends Y<? super HashSet<Int>, Number, Double, N>
ExtendsType extY1 = tf.getExtendsType(tf.getSimpleType("Y", tf.getSuperType(tf.getSimpleType("HashSet", "Int")), tf.getSimpleType("Number"), tf.getSimpleType("Double"), tf.getPlaceholderType("N")));
pairs.add(new MPair(ta, tb, PairOperator.SMALLER)); // Y<...> < buffer < X<...>
FiniteClosure fc = new FiniteClosure(pairs); fcb.add(x1, buffer);
fcb.add(buffer, y1);
IRuleSet rules = new RuleSet(fc); IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
MPair pair1 = new MPair(x2, extY1, PairOperator.SMALLERDOTWC);
MPair pair2 = new MPair(tf.getExtendsType(x2), extY1, PairOperator.SMALLERDOTWC);
MPair pair3 = new MPair(extY1, extY1, PairOperator.SMALLERDOTWC);
MPair test = new MPair(taa, new ExtendsType(tbb), PairOperator.SMALLERDOTWC); System.out.println("------ ReduceExt ------");
Optional<Set<MPair>> opt1 = rules.reduceExt(pair1);
System.out.println(opt1);
Optional<Set<MPair>> res = rules.reduceExt(test); Optional<Set<MPair>> opt2 = rules.reduceExt(pair2);
System.out.println(opt2);
//System.out.println(res); Optional<Set<MPair>> opt3 = rules.reduceExt(pair3);
System.out.println(opt3);
/*
* Negative Tests
*/
// Case 1: X <.? Y
pair1 = new MPair(x2, extY1.getExtendedType(), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair1).isPresent());
// Case 2: X =. ? super Y
pair2 = new MPair(x2, extY1, PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduceExt(pair2).isPresent());
// Case 3: ? extends Y <.? ? extends X
pair3 = new MPair(extY1, tf.getExtendsType(x2), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair3).isPresent());
// Case 4: X <. ? extends Y and ? extends Y not in grArg(X)
fcb.clear();
rules = new RuleSet(fcb.getFiniteClosure());
pair1 = new MPair(x2, extY1, PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair1).isPresent());
} }
@Test @Test
@ -280,7 +310,7 @@ public class RuleSetTest {
//X<Int, ? extends Double, M, N> //X<Int, ? extends Double, M, N>
SimpleType x2 = tf.getSimpleType("X", tf.getSimpleType("Int"), tf.getExtendsType(tf.getSimpleType("Double")), tf.getPlaceholderType("M"), tf.getPlaceholderType("N")); SimpleType x2 = tf.getSimpleType("X", tf.getSimpleType("Int"), tf.getExtendsType(tf.getSimpleType("Double")), tf.getPlaceholderType("M"), tf.getPlaceholderType("N"));
//? extends Y<? super HashSet<Int>, Number, Double, N> //? super Y<? super HashSet<Int>, Number, Double, N>
SuperType supY1 = tf.getSuperType(tf.getSimpleType("Y", tf.getSuperType(tf.getSimpleType("HashSet", "Int")), tf.getSimpleType("Number"), tf.getSimpleType("Double"), tf.getPlaceholderType("N"))); SuperType supY1 = tf.getSuperType(tf.getSimpleType("Y", tf.getSuperType(tf.getSimpleType("HashSet", "Int")), tf.getSimpleType("Number"), tf.getSimpleType("Double"), tf.getPlaceholderType("N")));
// Y<...> < buffer < X<...> // Y<...> < buffer < X<...>