fixed rule set test

This commit is contained in:
Florian Steurer 2016-04-14 14:21:19 +02:00
parent 3cd7dba316
commit e26f87afba

View File

@ -9,6 +9,7 @@ import junit.framework.Assert;
import org.junit.Test;
import de.dhbwstuttgart.typeinference.unify.RuleSet;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
@ -21,7 +22,7 @@ public class RuleSetTest {
@Test
public void testReduceUp() {
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
IRuleSet rules = new RuleSet();
TypeFactory tf = new TypeFactory();
/*
@ -59,7 +60,7 @@ public class RuleSetTest {
@Test
public void testReduceLow() {
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
IRuleSet rules = new RuleSet();
TypeFactory tf = new TypeFactory();
/*
@ -95,7 +96,7 @@ public class RuleSetTest {
@Test
public void testReduceUpLow() {
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
IRuleSet rules = new RuleSet();
TypeFactory tf = new TypeFactory();
/*
@ -153,15 +154,16 @@ public class RuleSetTest {
fcb.add(c1, buffer);
fcb.add(buffer, d1);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
IRuleSet rules = new RuleSet();
IFiniteClosure fc = fcb.getFiniteClosure();
UnifyPair pair = new UnifyPair(c2, d2, PairOperator.SMALLERDOT);
System.out.println("------ Reduce1 ------");
Optional<Set<UnifyPair>> res = rules.reduce1(pair);
Optional<Set<UnifyPair>> res = rules.reduce1(pair, fc);
System.out.println(res);
pair = new UnifyPair(c2, c2, PairOperator.SMALLERDOT);
res = rules.reduce1(pair);
res = rules.reduce1(pair, fc);
System.out.println(res);
/*
@ -170,24 +172,24 @@ public class RuleSetTest {
// Case 1: D <. C and C <* D
pair = new UnifyPair(d2, c2, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.reduce1(pair).isPresent());
Assert.assertFalse(rules.reduce1(pair, fc).isPresent());
// Case 2: D =. C
pair = new UnifyPair(c2, d2, PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduce1(pair).isPresent());
Assert.assertFalse(rules.reduce1(pair, fc).isPresent());
// Case 3: C <. D and !(C <* D)
fcb.clear();
rules = new RuleSet(fcb.getFiniteClosure());
fc = fcb.getFiniteClosure();
rules = new RuleSet();
pair = new UnifyPair(c1, d1, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.reduce1(pair).isPresent());
Assert.assertFalse(rules.reduce1(pair, fc).isPresent());
}
@Test
public void testReduce2() {
TypeFactory tf = new TypeFactory();
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
IRuleSet rules = new RuleSet();
/*
* Positive Tests
@ -253,19 +255,20 @@ public class RuleSetTest {
fcb.add(x1, buffer);
fcb.add(buffer, y1);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
IRuleSet rules = new RuleSet();
IFiniteClosure fc = fcb.getFiniteClosure();
UnifyPair pair1 = new UnifyPair(x2, extY1, PairOperator.SMALLERDOTWC);
UnifyPair pair2 = new UnifyPair(tf.getExtendsType(x2), extY1, PairOperator.SMALLERDOTWC);
UnifyPair pair3 = new UnifyPair(extY1, extY1, PairOperator.SMALLERDOTWC);
System.out.println("------ ReduceExt ------");
Optional<Set<UnifyPair>> opt1 = rules.reduceExt(pair1);
Optional<Set<UnifyPair>> opt1 = rules.reduceExt(pair1, fc);
System.out.println(opt1);
Optional<Set<UnifyPair>> opt2 = rules.reduceExt(pair2);
Optional<Set<UnifyPair>> opt2 = rules.reduceExt(pair2, fc);
System.out.println(opt2);
Optional<Set<UnifyPair>> opt3 = rules.reduceExt(pair3);
Optional<Set<UnifyPair>> opt3 = rules.reduceExt(pair3, fc);
System.out.println(opt3);
/*
@ -274,21 +277,22 @@ public class RuleSetTest {
// Case 1: X <.? Y
pair1 = new UnifyPair(x2, extY1.getExtendedType(), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair1).isPresent());
Assert.assertFalse(rules.reduceExt(pair1, fc).isPresent());
// Case 2: X =. ? super Y
pair2 = new UnifyPair(x2, extY1, PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduceExt(pair2).isPresent());
Assert.assertFalse(rules.reduceExt(pair2, fc).isPresent());
// Case 3: ? extends Y <.? ? extends X
pair3 = new UnifyPair(extY1, tf.getExtendsType(x2), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair3).isPresent());
Assert.assertFalse(rules.reduceExt(pair3, fc).isPresent());
// Case 4: X <. ? extends Y and ? extends Y not in grArg(X)
fcb.clear();
rules = new RuleSet(fcb.getFiniteClosure());
rules = new RuleSet();
fc = fcb.getFiniteClosure();
pair1 = new UnifyPair(x2, extY1, PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair1).isPresent());
Assert.assertFalse(rules.reduceExt(pair1, fc).isPresent());
}
@Test
@ -315,19 +319,20 @@ public class RuleSetTest {
fcb.add(y1, buffer);
fcb.add(buffer, x1);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
IRuleSet rules = new RuleSet();
IFiniteClosure fc = fcb.getFiniteClosure();
UnifyPair pair1 = new UnifyPair(x2, supY1, PairOperator.SMALLERDOTWC);
UnifyPair pair2 = new UnifyPair(tf.getSuperType(x2), supY1, PairOperator.SMALLERDOTWC);
UnifyPair pair3 = new UnifyPair(supY1, supY1, PairOperator.SMALLERDOTWC);
System.out.println("------ ReduceSup ------");
Optional<Set<UnifyPair>> opt1 = rules.reduceSup(pair1);
Optional<Set<UnifyPair>> opt1 = rules.reduceSup(pair1, fc);
System.out.println(opt1);
Optional<Set<UnifyPair>> opt2 = rules.reduceSup(pair2);
Optional<Set<UnifyPair>> opt2 = rules.reduceSup(pair2, fc);
System.out.println(opt2);
Optional<Set<UnifyPair>> opt3 = rules.reduceSup(pair3);
Optional<Set<UnifyPair>> opt3 = rules.reduceSup(pair3, fc);
System.out.println(opt3);
/*
@ -336,29 +341,29 @@ public class RuleSetTest {
// Case 1: X <.? Y
pair1 = new UnifyPair(x2, supY1.getSuperedType(), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceSup(pair1).isPresent());
Assert.assertFalse(rules.reduceSup(pair1, fc).isPresent());
// Case 2: X =. ? super Y
pair2 = new UnifyPair(x2, supY1, PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduceSup(pair2).isPresent());
Assert.assertFalse(rules.reduceSup(pair2, fc).isPresent());
// Case 3: ? super Y <.? ? super X
pair3 = new UnifyPair(supY1, tf.getSuperType(x2), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceSup(pair3).isPresent());
Assert.assertFalse(rules.reduceSup(pair3, fc).isPresent());
// Case 4: X <. ? super Y and ? super Y not in grArg(X)
fcb.clear();
rules = new RuleSet(fcb.getFiniteClosure());
rules = new RuleSet();
fc = fcb.getFiniteClosure();
pair1 = new UnifyPair(x2, supY1, PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceSup(pair1).isPresent());
Assert.assertFalse(rules.reduceSup(pair1, fc).isPresent());
}
@Test
public void testReduceEq() {
TypeFactory tf = new TypeFactory();
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
IRuleSet rules = new RuleSet();
/*
* Positive Tests
*/
@ -390,7 +395,8 @@ public class RuleSetTest {
@Test
public void testErase1() {
TypeFactory tf = new TypeFactory();
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getCollectionExample());
IRuleSet rules = new RuleSet();
IFiniteClosure fc = new FiniteClosureBuilder().getCollectionExample();
/*
* Positive Tests
@ -399,9 +405,9 @@ public class RuleSetTest {
UnifyPair erase2 = new UnifyPair(tf.getSimpleType("HashSet", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOT);
UnifyPair erase3 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
Assert.assertTrue(rules.erase1(erase1));
Assert.assertTrue(rules.erase1(erase2));
Assert.assertTrue(rules.erase1(erase3));
Assert.assertTrue(rules.erase1(erase1, fc));
Assert.assertTrue(rules.erase1(erase2, fc));
Assert.assertTrue(rules.erase1(erase3, fc));
/*
* Negative Tests
@ -410,15 +416,16 @@ public class RuleSetTest {
UnifyPair noerase2 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.EQUALSDOT);
UnifyPair noerase3 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.erase1(noerase1));
Assert.assertFalse(rules.erase1(noerase2));
Assert.assertFalse(rules.erase1(noerase3));
Assert.assertFalse(rules.erase1(noerase1, fc));
Assert.assertFalse(rules.erase1(noerase2, fc));
Assert.assertFalse(rules.erase1(noerase3, fc));
}
@Test
public void testErase2() {
TypeFactory tf = new TypeFactory();
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getCollectionExample());
IRuleSet rules = new RuleSet();
IFiniteClosure fc = new FiniteClosureBuilder().getCollectionExample();
/*
* Positive Tests
@ -430,11 +437,11 @@ public class RuleSetTest {
UnifyPair erase5 = new UnifyPair(tf.getSuperType(tf.getSimpleType("List", "T")), tf.getSuperType(tf.getSimpleType("Stack", "T")), PairOperator.SMALLERDOTWC);
Assert.assertTrue(rules.erase2(erase1));
Assert.assertTrue(rules.erase2(erase2));
Assert.assertTrue(rules.erase2(erase3));
Assert.assertTrue(rules.erase2(erase4));
Assert.assertTrue(rules.erase2(erase5));
Assert.assertTrue(rules.erase2(erase1, fc));
Assert.assertTrue(rules.erase2(erase2, fc));
Assert.assertTrue(rules.erase2(erase3, fc));
Assert.assertTrue(rules.erase2(erase4, fc));
Assert.assertTrue(rules.erase2(erase5, fc));
/*
* Negative Tests
@ -444,16 +451,16 @@ public class RuleSetTest {
UnifyPair noerase3 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("List", "T")), tf.getSuperType(tf.getSimpleType("List", "T")), PairOperator.SMALLERDOTWC);
UnifyPair noerase4 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
Assert.assertFalse(rules.erase2(noerase1));
Assert.assertFalse(rules.erase2(noerase2));
Assert.assertFalse(rules.erase2(noerase3));
Assert.assertFalse(rules.erase2(noerase4));
Assert.assertFalse(rules.erase2(noerase1, fc));
Assert.assertFalse(rules.erase2(noerase2, fc));
Assert.assertFalse(rules.erase2(noerase3, fc));
Assert.assertFalse(rules.erase2(noerase4, fc));
}
@Test
public void testErase3() {
TypeFactory tf = new TypeFactory();
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
IRuleSet rules = new RuleSet();
/*
* Positive Tests
@ -477,7 +484,7 @@ public class RuleSetTest {
@Test
public void testSwap() {
TypeFactory tf = new TypeFactory();
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
IRuleSet rules = new RuleSet();
/*
* Positive Tests
@ -528,7 +535,8 @@ public class RuleSetTest {
fcb.add(t1, t2);
fcb.add(t2, t3);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
IRuleSet rules = new RuleSet();
IFiniteClosure fc = fcb.getFiniteClosure();
/*
* Positive Tests
@ -543,9 +551,9 @@ public class RuleSetTest {
UnifyPair pair3 = new UnifyPair(c1, c3, PairOperator.SMALLERDOT);
System.out.println("------ Adapt ------");
System.out.println(rules.adapt(pair1));
System.out.println(rules.adapt(pair2));
System.out.println(rules.adapt(pair3));
System.out.println(rules.adapt(pair1, fc));
System.out.println(rules.adapt(pair2, fc));
System.out.println(rules.adapt(pair3, fc));
/*
* Negative Tests
@ -555,9 +563,9 @@ public class RuleSetTest {
UnifyPair noAdapt2 = new UnifyPair(c1, c1, PairOperator.SMALLERDOT);
UnifyPair noAdapt3 = new UnifyPair(c1, c2, PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.adapt(noAdapt1).isPresent());
Assert.assertFalse(rules.adapt(noAdapt2).isPresent());
Assert.assertFalse(rules.adapt(noAdapt3).isPresent());
Assert.assertFalse(rules.adapt(noAdapt1, fc).isPresent());
Assert.assertFalse(rules.adapt(noAdapt2, fc).isPresent());
Assert.assertFalse(rules.adapt(noAdapt3, fc).isPresent());
}
@Test
@ -575,7 +583,8 @@ public class RuleSetTest {
fcb.add(t2, t3);
fcb.add(t32, t4);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
IRuleSet rules = new RuleSet();
IFiniteClosure fc = fcb.getFiniteClosure();
/*
* Positive Tests
@ -597,13 +606,13 @@ public class RuleSetTest {
UnifyPair pair7 = new UnifyPair(extc1, extc1, PairOperator.SMALLERDOTWC);
System.out.println("------ AdaptExt ------");
System.out.println(rules.adaptExt(pair1));
System.out.println(rules.adaptExt(pair2));
System.out.println(rules.adaptExt(pair3));
System.out.println(rules.adaptExt(pair4));
System.out.println(rules.adaptExt(pair5));
System.out.println(rules.adaptExt(pair6));
System.out.println(rules.adaptExt(pair7));
System.out.println(rules.adaptExt(pair1, fc));
System.out.println(rules.adaptExt(pair2, fc));
System.out.println(rules.adaptExt(pair3, fc));
System.out.println(rules.adaptExt(pair4, fc));
System.out.println(rules.adaptExt(pair5, fc));
System.out.println(rules.adaptExt(pair6, fc));
System.out.println(rules.adaptExt(pair7, fc));
/*
* Negative Tests
@ -615,11 +624,11 @@ public class RuleSetTest {
UnifyPair noAdapt4 = new UnifyPair(extc3, extc1, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt5 = new UnifyPair(c1, extc2, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.adaptExt(noAdapt1).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt2).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt3).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt4).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt5).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt1, fc).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt2, fc).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt3, fc).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt4, fc).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt5, fc).isPresent());
}
@Test
@ -637,7 +646,8 @@ public class RuleSetTest {
fcb.add(t2, t3);
fcb.add(t32, t4);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
IRuleSet rules = new RuleSet();
IFiniteClosure fc = fcb.getFiniteClosure();
/*
* Positive Tests
@ -659,13 +669,13 @@ public class RuleSetTest {
UnifyPair pair7 = new UnifyPair(supc1, supc1, PairOperator.SMALLERDOTWC);
System.out.println("------ AdaptSup ------");
System.out.println(rules.adaptSup(pair1));
System.out.println(rules.adaptSup(pair2));
System.out.println(rules.adaptSup(pair3));
System.out.println(rules.adaptSup(pair4));
System.out.println(rules.adaptSup(pair5));
System.out.println(rules.adaptSup(pair6));
System.out.println(rules.adaptSup(pair7));
System.out.println(rules.adaptSup(pair1, fc));
System.out.println(rules.adaptSup(pair2, fc));
System.out.println(rules.adaptSup(pair3, fc));
System.out.println(rules.adaptSup(pair4, fc));
System.out.println(rules.adaptSup(pair5, fc));
System.out.println(rules.adaptSup(pair6, fc));
System.out.println(rules.adaptSup(pair7, fc));
/*
* Negative Tests
@ -677,10 +687,10 @@ public class RuleSetTest {
UnifyPair noAdapt4 = new UnifyPair(supc3, supc1, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt5 = new UnifyPair(c1, supc2, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.adaptExt(noAdapt1).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt2).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt3).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt4).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt5).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt1, fc).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt2, fc).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt3, fc).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt4, fc).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt5, fc).isPresent());
}
}