2015-11-07 09:57:17 +00:00
|
|
|
package unify;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2015-11-07 19:37:29 +00:00
|
|
|
import junit.framework.Assert;
|
|
|
|
|
2015-11-07 09:57:17 +00:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
|
|
|
|
import de.dhbwstuttgart.typeinference.unifynew.RuleSet;
|
2015-11-07 15:49:20 +00:00
|
|
|
import de.dhbwstuttgart.typinference.unify.model.ExtendsType;
|
2015-11-07 09:57:17 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
public class RuleSetTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testReduceUp() {
|
2015-11-08 16:02:25 +00:00
|
|
|
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
|
|
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Positive Tests
|
|
|
|
*/
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 16:02:25 +00:00
|
|
|
MPair reduce1 = new MPair(tf.getSimpleType("type"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
|
|
|
|
MPair reduce2 = new MPair(tf.getPlaceholderType("T"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
|
|
|
|
|
|
|
|
MPair expected1 = new MPair(tf.getSimpleType("type"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
|
|
|
|
MPair expected2 = new MPair(tf.getPlaceholderType("T"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 16:02:25 +00:00
|
|
|
Optional<MPair> opt1 = rules.reduceUp(reduce1);
|
|
|
|
Optional<MPair> opt2 = rules.reduceUp(reduce2);
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 16:02:25 +00:00
|
|
|
Assert.assertTrue(opt1.isPresent());
|
|
|
|
Assert.assertTrue(opt2.isPresent());
|
|
|
|
Assert.assertEquals(opt1.get(), expected1);
|
|
|
|
Assert.assertEquals(opt2.get(), expected2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Negative Tests
|
|
|
|
*/
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 16:02:25 +00:00
|
|
|
MPair noreduce1 = new MPair(tf.getSuperType(tf.getSimpleType("type")), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
|
|
|
|
MPair noreduce2 = new MPair(tf.getPlaceholderType("T"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
|
|
|
|
MPair noreduce3 = new MPair(tf.getPlaceholderType("T"), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
|
|
|
|
MPair noreduce4 = new MPair(tf.getPlaceholderType("T"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.EQUALSDOT);
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 16:02:25 +00:00
|
|
|
Assert.assertFalse(rules.reduceUp(noreduce1).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceUp(noreduce2).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceUp(noreduce3).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceUp(noreduce4).isPresent());
|
2015-11-07 09:57:17 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 15:49:20 +00:00
|
|
|
@Test
|
|
|
|
public void testReduceLow() {
|
2015-11-08 16:02:25 +00:00
|
|
|
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
|
|
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Positive Tests
|
|
|
|
*/
|
|
|
|
MPair reduce1 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
|
|
|
|
MPair reduce2 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), 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<MPair> opt1 = rules.reduceLow(reduce1);
|
|
|
|
Optional<MPair> opt2 = rules.reduceLow(reduce2);
|
2015-11-07 15:49:20 +00:00
|
|
|
|
2015-11-08 16:02:25 +00:00
|
|
|
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.getPlaceholderType("T"), 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.reduceLow(noreduce1).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceLow(noreduce2).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceLow(noreduce3).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceLow(noreduce4).isPresent());
|
2015-11-07 15:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testReduceUpLow() {
|
2015-11-08 16:05:35 +00:00
|
|
|
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<MPair> opt1 = rules.reduceUpLow(reduce1);
|
|
|
|
Optional<MPair> 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);
|
2015-11-07 15:49:20 +00:00
|
|
|
|
2015-11-08 16:05:35 +00:00
|
|
|
Assert.assertFalse(rules.reduceUpLow(noreduce1).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceUpLow(noreduce2).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceUpLow(noreduce3).isPresent());
|
|
|
|
Assert.assertFalse(rules.reduceUpLow(noreduce4).isPresent());
|
2015-11-07 15:49:20 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 09:57:17 +00:00
|
|
|
@Test
|
|
|
|
public void testReduce1() {
|
2015-11-08 20:23:20 +00:00
|
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
/*
|
|
|
|
* Positive Tests
|
|
|
|
*/
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
// C<T1, T2, T3, T4>
|
|
|
|
SimpleType c1 = tf.getSimpleType("C", "T1", "T2", "T3", "T4");
|
|
|
|
// D<T4, T1, T2, T3>
|
|
|
|
SimpleType d1 = tf.getSimpleType("D", "T4", "T1", "T2", "T3");
|
|
|
|
SimpleType buffer = tf.getSimpleType("Buffer");
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
//C<Int, ? extends Double, M, N>
|
|
|
|
SimpleType c2 = tf.getSimpleType("C", tf.getSimpleType("Int"), tf.getExtendsType(tf.getSimpleType("Double")), tf.getPlaceholderType("M"), tf.getPlaceholderType("N"));
|
|
|
|
//D<? super HashSet<Int>, Number, Double, N>
|
|
|
|
SimpleType d2 = tf.getSimpleType("D", tf.getSuperType(tf.getSimpleType("HashSet", "Int")), tf.getSimpleType("Number"), tf.getSimpleType("Double"), tf.getPlaceholderType("N"));
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
// C<...> < buffer < D<...>
|
|
|
|
fcb.add(c1, buffer);
|
|
|
|
fcb.add(buffer, d1);
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
|
|
|
|
MPair pair = new MPair(c2, d2, PairOperator.SMALLERDOT);
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
System.out.println("------ Reduce1 ------");
|
|
|
|
Optional<Set<MPair>> res = rules.reduce1(pair);
|
|
|
|
System.out.println(res);
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
pair = new MPair(c2, c2, PairOperator.SMALLERDOT);
|
|
|
|
res = rules.reduce1(pair);
|
2015-11-07 09:57:17 +00:00
|
|
|
System.out.println(res);
|
2015-11-08 20:23:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Negative Tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Case 1: D <. C and C <* D
|
|
|
|
pair = new MPair(d2, c2, PairOperator.SMALLERDOT);
|
|
|
|
Assert.assertFalse(rules.reduce1(pair).isPresent());
|
|
|
|
|
|
|
|
// Case 2: D =. C
|
|
|
|
pair = new MPair(c2, d2, PairOperator.EQUALSDOT);
|
|
|
|
Assert.assertFalse(rules.reduce1(pair).isPresent());
|
|
|
|
|
|
|
|
// Case 3: C <. D and !(C <* D)
|
|
|
|
fcb.clear();
|
|
|
|
rules = new RuleSet(fcb.getFiniteClosure());
|
|
|
|
pair = new MPair(c1, d1, PairOperator.SMALLERDOT);
|
|
|
|
Assert.assertFalse(rules.reduce1(pair).isPresent());
|
2015-11-07 09:57:17 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 15:49:20 +00:00
|
|
|
@Test
|
|
|
|
public void testReduce2() {
|
|
|
|
|
|
|
|
}
|
2015-11-07 09:57:17 +00:00
|
|
|
|
2015-11-07 15:49:20 +00:00
|
|
|
@Test
|
|
|
|
public void testReduceExt() {
|
|
|
|
Set<MPair> pairs = new HashSet<MPair>();
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
pairs.add(new MPair(ta, tb, PairOperator.SMALLER));
|
|
|
|
FiniteClosure fc = new FiniteClosure(pairs);
|
|
|
|
|
|
|
|
IRuleSet rules = new RuleSet(fc);
|
|
|
|
|
|
|
|
MPair test = new MPair(taa, new ExtendsType(tbb), PairOperator.SMALLERDOTWC);
|
|
|
|
|
|
|
|
Optional<Set<MPair>> res = rules.reduceExt(test);
|
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
//System.out.println(res);
|
2015-11-07 15:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testReduceSup() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testReduceEq() {
|
2015-11-08 20:23:20 +00:00
|
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
|
|
|
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Positive Tests
|
|
|
|
*/
|
|
|
|
System.out.println("----- ReduceEq ------");
|
|
|
|
|
|
|
|
// C<T1, SType1, ? extends SType1>
|
|
|
|
SimpleType c1 = tf.getSimpleType("C", tf.getPlaceholderType("T1"), tf.getSimpleType("SType1"), tf.getExtendsType(tf.getSimpleType("SType1")));
|
|
|
|
// D<T2, SType2, ? extends SType2>
|
|
|
|
SimpleType c2 = tf.getSimpleType("C", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2")));
|
|
|
|
|
|
|
|
MPair pair = new MPair(c1, c2, PairOperator.SMALLERDOTWC);
|
|
|
|
Optional<Set<MPair>> res = rules.reduceEq(pair);
|
|
|
|
System.out.println(res);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Negative Tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Case 1: D <.? C
|
|
|
|
SimpleType d1 = tf.getSimpleType("D", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2")));
|
|
|
|
pair = new MPair(d1, c1, PairOperator.SMALLERDOTWC);
|
|
|
|
Assert.assertFalse(rules.reduceEq(pair).isPresent());
|
2015-11-07 15:49:20 +00:00
|
|
|
|
2015-11-08 20:23:20 +00:00
|
|
|
// Case 2: C <. C
|
|
|
|
pair = new MPair(c1, c2, PairOperator.SMALLERDOT);
|
|
|
|
Assert.assertFalse(rules.reduceEq(pair).isPresent());
|
2015-11-07 15:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testErase1() {
|
2015-11-08 15:29:40 +00:00
|
|
|
TypeFactory tf = new TypeFactory();
|
2015-11-08 16:02:25 +00:00
|
|
|
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getCollectionExample());
|
2015-11-08 15:29:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Positive Tests
|
|
|
|
*/
|
|
|
|
MPair erase1 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOT);
|
|
|
|
MPair erase2 = new MPair(tf.getSimpleType("HashSet", "W"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOT);
|
|
|
|
MPair erase3 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
|
2015-11-07 15:49:20 +00:00
|
|
|
|
2015-11-08 15:29:40 +00:00
|
|
|
Assert.assertTrue(rules.erase1(erase1));
|
|
|
|
Assert.assertTrue(rules.erase1(erase2));
|
|
|
|
Assert.assertTrue(rules.erase1(erase3));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Negative Tests
|
|
|
|
*/
|
|
|
|
MPair noerase1 = new MPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
|
|
|
|
MPair noerase2 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.EQUALSDOT);
|
|
|
|
MPair noerase3 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOTWC);
|
|
|
|
|
|
|
|
Assert.assertFalse(rules.erase1(noerase1));
|
|
|
|
Assert.assertFalse(rules.erase1(noerase2));
|
|
|
|
Assert.assertFalse(rules.erase1(noerase3));
|
2015-11-07 15:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testErase2() {
|
2015-11-08 15:29:40 +00:00
|
|
|
TypeFactory tf = new TypeFactory();
|
2015-11-08 16:02:25 +00:00
|
|
|
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getCollectionExample());
|
2015-11-07 15:49:20 +00:00
|
|
|
|
2015-11-08 15:29:40 +00:00
|
|
|
/*
|
|
|
|
* Positive Tests
|
|
|
|
*/
|
|
|
|
MPair erase1 = new MPair(tf.getSimpleType("List", "T"), tf.getExtendsType(tf.getSimpleType("Collection")), PairOperator.SMALLERDOTWC);
|
|
|
|
MPair erase2 = new MPair(tf.getSimpleType("Collection"), tf.getSuperType(tf.getSimpleType("HashSet", "T")), PairOperator.SMALLERDOTWC);
|
|
|
|
MPair erase3 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOTWC);
|
|
|
|
MPair erase4 = new MPair(tf.getExtendsType(tf.getSimpleType("LinkedList", "T")), tf.getExtendsType(tf.getSimpleType("List", "T")), PairOperator.SMALLERDOTWC);
|
|
|
|
MPair erase5 = new MPair(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));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Negative Tests
|
|
|
|
*/
|
|
|
|
MPair noerase1 = new MPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOTWC);
|
|
|
|
MPair noerase2 = new MPair(tf.getSuperType(tf.getSimpleType("List", "T")), tf.getSimpleType("ArrayList", "T"), PairOperator.SMALLERDOTWC);
|
|
|
|
MPair noerase3 = new MPair(tf.getExtendsType(tf.getSimpleType("List", "T")), tf.getSuperType(tf.getSimpleType("List", "T")), PairOperator.SMALLERDOTWC);
|
|
|
|
MPair noerase4 = new MPair(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));
|
2015-11-07 15:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testErase3() {
|
2015-11-08 15:42:57 +00:00
|
|
|
TypeFactory tf = new TypeFactory();
|
2015-11-08 16:02:25 +00:00
|
|
|
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
|
2015-11-08 15:42:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Positive Tests
|
|
|
|
*/
|
|
|
|
MPair erase1 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.EQUALSDOT);
|
|
|
|
MPair erase2 = new MPair(tf.getPlaceholderType("W"), tf.getPlaceholderType("W"), PairOperator.EQUALSDOT);
|
|
|
|
|
|
|
|
Assert.assertTrue(rules.erase3(erase1));
|
|
|
|
Assert.assertTrue(rules.erase3(erase2));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Negative Tests
|
|
|
|
*/
|
|
|
|
MPair noerase1 = new MPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.EQUALSDOT);
|
|
|
|
MPair noerase2 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
|
2015-11-07 15:49:20 +00:00
|
|
|
|
2015-11-08 15:42:57 +00:00
|
|
|
Assert.assertFalse(rules.erase3(noerase1));
|
|
|
|
Assert.assertFalse(rules.erase3(noerase2));
|
2015-11-07 15:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSwap() {
|
2015-11-07 19:37:29 +00:00
|
|
|
TypeFactory tf = new TypeFactory();
|
2015-11-08 16:02:25 +00:00
|
|
|
IRuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
|
2015-11-07 19:37:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Positive Tests
|
|
|
|
*/
|
|
|
|
MPair swap1 = new MPair(tf.getExtendsType(tf.getSimpleType("MyClass")), tf.getPlaceholderType("P"), PairOperator.EQUALSDOT);
|
|
|
|
MPair swap2 = new MPair(tf.getSimpleType("MyClass"), tf.getPlaceholderType("X"), PairOperator.EQUALSDOT);
|
|
|
|
|
|
|
|
MPair expected1 = new MPair(tf.getPlaceholderType("P"), tf.getExtendsType(tf.getSimpleType("MyClass")), PairOperator.EQUALSDOT);
|
|
|
|
MPair expected2 = new MPair(tf.getPlaceholderType("X"), tf.getSimpleType("MyClass"), PairOperator.EQUALSDOT);
|
|
|
|
|
|
|
|
Optional<MPair> opt1 = rules.swap(swap1);
|
|
|
|
Optional<MPair> opt2 = rules.swap(swap2);
|
|
|
|
|
2015-11-08 15:29:40 +00:00
|
|
|
// swap((? extends MyClass =. P)) = (P =. MyClass)
|
2015-11-07 19:37:29 +00:00
|
|
|
Assert.assertEquals(opt1.get(), expected1);
|
2015-11-08 15:29:40 +00:00
|
|
|
|
|
|
|
// swap((MyClass =. X)) = (X =. MyClass)
|
2015-11-07 19:37:29 +00:00
|
|
|
Assert.assertEquals(opt2.get(), expected2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Negative Tests
|
|
|
|
*/
|
|
|
|
MPair noswap1 = new MPair(tf.getPlaceholderType("Z"), tf.getPlaceholderType("X"), PairOperator.EQUALSDOT);
|
|
|
|
MPair noswap2 = new MPair(tf.getSimpleType("MyClass"), tf.getExtendsType(tf.getPlaceholderType("X")), PairOperator.EQUALSDOT);
|
|
|
|
MPair noswap3 = new MPair( tf.getPlaceholderType("X"), tf.getSimpleType("MyClass"), PairOperator.EQUALSDOT);
|
|
|
|
MPair noswap4 = new MPair(tf.getSimpleType("MyClass"), tf.getPlaceholderType("X"), PairOperator.SMALLERDOT);
|
|
|
|
|
|
|
|
opt1 = rules.swap(noswap1);
|
|
|
|
opt2 = rules.swap(noswap2);
|
|
|
|
Optional<MPair> opt3 = rules.swap(noswap3);
|
|
|
|
Optional<MPair> opt4 = rules.swap(noswap4);
|
|
|
|
|
|
|
|
Assert.assertFalse(opt1.isPresent());
|
|
|
|
Assert.assertFalse(opt2.isPresent());
|
|
|
|
Assert.assertFalse(opt3.isPresent());
|
|
|
|
Assert.assertFalse(opt4.isPresent());
|
2015-11-07 15:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAdapt() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAdaptExt() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAdaptSup() {
|
|
|
|
|
|
|
|
}
|
2015-11-07 09:57:17 +00:00
|
|
|
}
|