swap rule test
This commit is contained in:
parent
84641d4abf
commit
1b1fae6b13
@ -62,7 +62,7 @@ public class Unify {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void splitEq(Set<MPair> eq, Set<MPair> eq1s, Set<MPair> eq2s) {
|
||||
protected void splitEq(Set<MPair> eq, Set<MPair> eq1s, Set<MPair> eq2s) {
|
||||
for(MPair pair : eq)
|
||||
if(pair.getLhsType() instanceof PlaceholderType && pair.getRhsType() instanceof PlaceholderType)
|
||||
eq1s.add(pair);
|
||||
@ -70,7 +70,7 @@ public class Unify {
|
||||
eq2s.add(pair);
|
||||
}
|
||||
|
||||
private Set<MPair> applyTypeUnificationRules(Set<MPair> eq, IFiniteClosure fc) {
|
||||
protected Set<MPair> applyTypeUnificationRules(Set<MPair> eq, IFiniteClosure fc) {
|
||||
|
||||
/*
|
||||
* Rule Application Strategy:
|
||||
@ -133,7 +133,7 @@ public class Unify {
|
||||
return targetSet;
|
||||
}
|
||||
|
||||
private void swapAddOrErase(MPair pair, IRuleSet rules, Collection<MPair> collection) {
|
||||
protected void swapAddOrErase(MPair pair, IRuleSet rules, Collection<MPair> collection) {
|
||||
Optional<MPair> opt = rules.swap(pair);
|
||||
MPair pair2 = opt.isPresent() ? opt.get() : pair;
|
||||
|
||||
|
@ -34,4 +34,21 @@ public class TypeParams implements Iterable<Type>{
|
||||
public Iterator<Type> iterator() {
|
||||
return Arrays.stream(typeParams).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(typeParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof TypeParams))
|
||||
return false;
|
||||
|
||||
TypeParams other = (TypeParams) obj;
|
||||
|
||||
// TODO
|
||||
return other.size() == this.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,12 @@
|
||||
package unify;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typinference.unify.model.MPair;
|
||||
import de.dhbwstuttgart.typinference.unify.model.Type;
|
||||
|
||||
public class FiniteClosureTest {
|
||||
@ -11,7 +15,7 @@ public class FiniteClosureTest {
|
||||
public void testGreater() {
|
||||
IFiniteClosure fc = new FiniteClosureBuilder().getCollectionExample();
|
||||
TypeFactory tf = new TypeFactory();
|
||||
|
||||
|
||||
System.out.println("\n\n----- Greater Test -----");
|
||||
System.out.println("Greater(LinkedList<T>) = " + fc.greater(tf.getSimpleType("LinkedList", "T")));
|
||||
System.out.println("Greater(TreeSet<T>) = " + fc.greater(tf.getSimpleType("TreeSet", "T")));
|
||||
|
@ -5,6 +5,8 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
|
||||
@ -149,7 +151,41 @@ public class RuleSetTest {
|
||||
|
||||
@Test
|
||||
public void testSwap() {
|
||||
TypeFactory tf = new TypeFactory();
|
||||
RuleSet rules = new RuleSet(new FiniteClosureBuilder().getFiniteClosure());
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
Assert.assertEquals(opt1.get(), expected1);
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -14,7 +14,7 @@ import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
|
||||
public class UnifyTest {
|
||||
public class UnifyOldTest {
|
||||
|
||||
@Test
|
||||
public void unifyTestSimpleTypes() {
|
Loading…
Reference in New Issue
Block a user