erase1 and erase2 tests
This commit is contained in:
parent
1b1fae6b13
commit
2eb11748ca
@ -280,7 +280,7 @@ public class RuleSet implements IRuleSet{
|
||||
if(!(rhsType instanceof SimpleType) && !(rhsType instanceof PlaceholderType))
|
||||
return false;
|
||||
|
||||
return finiteClosure.smaller(lhsType).contains(rhsType);
|
||||
return finiteClosure.greater(lhsType).contains(rhsType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -288,15 +288,10 @@ public class RuleSet implements IRuleSet{
|
||||
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
|
||||
return false;
|
||||
|
||||
Type lhsType = pair.getLhsType();
|
||||
if(!(lhsType instanceof SimpleType) && !(lhsType instanceof PlaceholderType))
|
||||
return false;
|
||||
|
||||
Type lhsType = pair.getLhsType();
|
||||
Type rhsType = pair.getRhsType();
|
||||
if(!(rhsType instanceof ExtendsType))
|
||||
return false;
|
||||
|
||||
return finiteClosure.grArg(lhsType).contains(((ExtendsType) rhsType).getExtendedType());
|
||||
return finiteClosure.grArg(lhsType).contains(rhsType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,4 +34,18 @@ public class ExtendsType extends Type {
|
||||
public Set<Type> grArg(IFiniteClosure fc) {
|
||||
return fc.grArg(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return extendedType.hashCode() + 17;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof ExtendsType))
|
||||
return false;
|
||||
|
||||
ExtendsType other = (ExtendsType) obj;
|
||||
return other.getExtendedType().equals(extendedType);
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,17 @@ public class PlaceholderType extends Type{
|
||||
public Set<Type> grArg(IFiniteClosure fc) {
|
||||
return fc.grArg(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return typeName.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof PlaceholderType))
|
||||
return false;
|
||||
|
||||
return ((PlaceholderType) obj).getName().equals(typeName);
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,22 @@ public class SimpleType extends Type {
|
||||
public Set<Type> grArg(IFiniteClosure fc) {
|
||||
return fc.grArg(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return typeName.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof SimpleType))
|
||||
return false;
|
||||
|
||||
SimpleType other = (SimpleType) obj;
|
||||
|
||||
if(!other.getName().equals(typeName))
|
||||
return false;
|
||||
|
||||
return other.getTypeParams().equals(typeParams);
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,18 @@ public class SuperType extends Type {
|
||||
public Set<Type> grArg(IFiniteClosure fc) {
|
||||
return fc.grArg(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return superedType.hashCode() + 17;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof SuperType))
|
||||
return false;
|
||||
|
||||
SuperType other = (SuperType) obj;
|
||||
return other.getSuperedType().equals(superedType);
|
||||
}
|
||||
}
|
||||
|
@ -21,31 +21,10 @@ public abstract class Type {
|
||||
public TypeParams getTypeParams() {
|
||||
return typeParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Type))
|
||||
return false;
|
||||
if(obj.hashCode() != hashCode())
|
||||
return false;
|
||||
|
||||
Type other = (Type) obj;
|
||||
|
||||
if(!other.getName().equals(typeName))
|
||||
return false;
|
||||
|
||||
return other.getTypeParams().equals(typeParams);
|
||||
}
|
||||
|
||||
public abstract Set<Type> smArg(IFiniteClosure fc);
|
||||
|
||||
public abstract Set<Type> grArg(IFiniteClosure fc);
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return typeName.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -136,12 +136,65 @@ public class RuleSetTest {
|
||||
|
||||
@Test
|
||||
public void testErase1() {
|
||||
TypeFactory tf = new TypeFactory();
|
||||
RuleSet rules = new RuleSet(new FiniteClosureBuilder().getCollectionExample());
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErase2() {
|
||||
TypeFactory tf = new TypeFactory();
|
||||
RuleSet rules = new RuleSet(new FiniteClosureBuilder().getCollectionExample());
|
||||
|
||||
/*
|
||||
* 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));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -166,7 +219,10 @@ public class RuleSetTest {
|
||||
Optional<MPair> opt1 = rules.swap(swap1);
|
||||
Optional<MPair> opt2 = rules.swap(swap2);
|
||||
|
||||
// swap((? extends MyClass =. P)) = (P =. MyClass)
|
||||
Assert.assertEquals(opt1.get(), expected1);
|
||||
|
||||
// swap((MyClass =. X)) = (X =. MyClass)
|
||||
Assert.assertEquals(opt2.get(), expected2);
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user