diff --git a/test/unify/RuleSetTest.java b/test/unify/RuleSetTest.java index d76546a0..65fdb19f 100644 --- a/test/unify/RuleSetTest.java +++ b/test/unify/RuleSetTest.java @@ -16,7 +16,6 @@ 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 { @@ -97,7 +96,38 @@ public class RuleSetTest { @Test public void testReduceUpLow() { + IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure()); + TypeFactory tf = new TypeFactory(); + + /* + * Positive Tests + */ + MPair reduce1 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT); + MPair reduce2 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSuperType(tf.getPlaceholderType("T")), PairOperator.SMALLERDOT); + + MPair expected1 = new MPair(tf.getSimpleType("type"), tf.getSimpleType("type"), PairOperator.SMALLERDOT); + MPair expected2 = new MPair(tf.getSimpleType("type"), tf.getPlaceholderType("T"), PairOperator.SMALLERDOT); + Optional opt1 = rules.reduceUpLow(reduce1); + Optional opt2 = rules.reduceUpLow(reduce2); + + Assert.assertTrue(opt1.isPresent()); + Assert.assertTrue(opt2.isPresent()); + Assert.assertEquals(opt1.get(), expected1); + Assert.assertEquals(opt2.get(), expected2); + + /* + * Negative Tests + */ + MPair noreduce1 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT); + MPair noreduce2 = new MPair(tf.getSuperType(tf.getPlaceholderType("T")), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT); + MPair noreduce3 = new MPair(tf.getSuperType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.SMALLERDOT); + MPair noreduce4 = new MPair(tf.getExtendsType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.EQUALSDOT); + + Assert.assertFalse(rules.reduceUpLow(noreduce1).isPresent()); + Assert.assertFalse(rules.reduceUpLow(noreduce2).isPresent()); + Assert.assertFalse(rules.reduceUpLow(noreduce3).isPresent()); + Assert.assertFalse(rules.reduceUpLow(noreduce4).isPresent()); } @Test