From 7ada9cbd4740fbad247054f040aca795863fd591 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Sun, 8 Nov 2015 21:41:24 +0100 Subject: [PATCH] reduce 2 Test --- test/unify/RuleSetTest.java | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test/unify/RuleSetTest.java b/test/unify/RuleSetTest.java index 0776b2b1..26aefa59 100644 --- a/test/unify/RuleSetTest.java +++ b/test/unify/RuleSetTest.java @@ -16,6 +16,7 @@ import de.dhbwstuttgart.typinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typinference.unify.model.MPair; import de.dhbwstuttgart.typinference.unify.model.MPair.PairOperator; import de.dhbwstuttgart.typinference.unify.model.SimpleType; +import de.dhbwstuttgart.typinference.unify.model.SuperType; public class RuleSetTest { @@ -186,7 +187,48 @@ public class RuleSetTest { @Test public void testReduce2() { + TypeFactory tf = new TypeFactory(); + FiniteClosureBuilder fcb = new FiniteClosureBuilder(); + IRuleSet rules = new RuleSet(fcb.getFiniteClosure()); + /* + * Positive Tests + */ + System.out.println("----- Reduce2 ------"); + + // C + SimpleType c1 = tf.getSimpleType("C", tf.getPlaceholderType("T1"), tf.getSimpleType("SType1"), tf.getExtendsType(tf.getSimpleType("SType1"))); + // C + SimpleType c2 = tf.getSimpleType("C", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2"))); + + MPair pair1 = new MPair(c1, c2, PairOperator.EQUALSDOT); + MPair pair2 = new MPair(tf.getExtendsType(c1), tf.getExtendsType(c2), PairOperator.EQUALSDOT); + MPair pair3 = new MPair(tf.getSuperType(c1), tf.getSuperType(c2), PairOperator.EQUALSDOT); + + Optional> opt1 = rules.reduce2(pair1); + System.out.println(opt1); + + Optional> opt2 = rules.reduce2(pair2); + System.out.println(opt2); + + Optional> opt3 = rules.reduce2(pair3); + System.out.println(opt3); + + + /* + * Negative Tests + */ + + SimpleType d1 = tf.getSimpleType("D", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2"))); + pair1 = new MPair(d1, c1, PairOperator.EQUALSDOT); // Case 1: D =. C + pair2 = new MPair(tf.getExtendsType(c1), c2, PairOperator.EQUALSDOT); // Case 2: ? extends C =. C + pair3 = new MPair(tf.getExtendsType(c1), tf.getSuperType(c2), PairOperator.EQUALSDOT); // Case 3: ? extends C =. ? super C + MPair pair4 = new MPair(c1, c2, PairOperator.SMALLERDOT); // Case 4: C <. C + + Assert.assertFalse(rules.reduceEq(pair1).isPresent()); + Assert.assertFalse(rules.reduceEq(pair2).isPresent()); + Assert.assertFalse(rules.reduceEq(pair3).isPresent()); + Assert.assertFalse(rules.reduceEq(pair4).isPresent()); } @Test @@ -239,7 +281,7 @@ public class RuleSetTest { // C SimpleType c1 = tf.getSimpleType("C", tf.getPlaceholderType("T1"), tf.getSimpleType("SType1"), tf.getExtendsType(tf.getSimpleType("SType1"))); - // D + // C SimpleType c2 = tf.getSimpleType("C", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2"))); MPair pair = new MPair(c1, c2, PairOperator.SMALLERDOTWC);