diff --git a/test/unify/RuleSetTest.java b/test/unify/RuleSetTest.java index 754e3a25..b44e62ce 100644 --- a/test/unify/RuleSetTest.java +++ b/test/unify/RuleSetTest.java @@ -233,34 +233,64 @@ public class RuleSetTest { @Test public void testReduceExt() { - Set pairs = new HashSet(); + TypeFactory tf = new TypeFactory(); + FiniteClosureBuilder fcb = new FiniteClosureBuilder(); - SimpleType t1 = new SimpleType("t1"); - SimpleType t2 = new SimpleType("t2"); - 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"); + /* + * Positive Tests + */ - SimpleType ta = new SimpleType("a", t1, t2, t3); - SimpleType taa = new SimpleType("a", t4, t5, t6); - SimpleType tb = new SimpleType("b", t3, t1, t2); - SimpleType tbb = new SimpleType("b", t7, t8, t9); + // X + SimpleType x1 = tf.getSimpleType("X", "T1", "T2", "T3", "T4"); + // Y + SimpleType y1 = tf.getSimpleType("Y", "T4", "T1", "T2", "T3"); + SimpleType buffer = tf.getSimpleType("Buffer"); + //X + SimpleType x2 = tf.getSimpleType("X", tf.getSimpleType("Int"), tf.getExtendsType(tf.getSimpleType("Double")), tf.getPlaceholderType("M"), tf.getPlaceholderType("N")); + //? extends Y, 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)); - FiniteClosure fc = new FiniteClosure(pairs); + // Y<...> < buffer < X<...> + 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> opt1 = rules.reduceExt(pair1); + System.out.println(opt1); - Optional> res = rules.reduceExt(test); + Optional> opt2 = rules.reduceExt(pair2); + System.out.println(opt2); - //System.out.println(res); + Optional> 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 @@ -280,7 +310,7 @@ public class RuleSetTest { //X SimpleType x2 = tf.getSimpleType("X", tf.getSimpleType("Int"), tf.getExtendsType(tf.getSimpleType("Double")), tf.getPlaceholderType("M"), tf.getPlaceholderType("N")); - //? extends Y, Number, Double, N> + //? super Y, 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"))); // Y<...> < buffer < X<...>