JavaTXCompilerInJavaTX/test/strucType/TestStrucTypeUnifyUtils.java

47 lines
1.5 KiB
Java

package strucType;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.junit.Test;
import de.dhbwstuttgart.strucTypes.StrucTypeUnifyUtils;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import junit.framework.Assert;
public class TestStrucTypeUnifyUtils {
@Test
public void testLinkPairs() {
List<UnifyPair> pairs = new ArrayList<>();
ReferenceType t = new ReferenceType("t");
PlaceholderType T1 = new PlaceholderType("T1");
PlaceholderType T2 = new PlaceholderType("T2");
PlaceholderType T3 = new PlaceholderType("T3");
UnifyPair p1 = UnifyTypeFactory.generateSmallerDotPair(t, T1);
UnifyPair p2 = UnifyTypeFactory.generateSmallerDotPair(T1, T3);
UnifyPair p3 = UnifyTypeFactory.generateSmallerDotPair(T1, T2);
UnifyPair p4 = UnifyTypeFactory.generateSmallerDotPair(T2, t);
pairs.add(p1);
pairs.add(p2);
pairs.add(p3);
pairs.add(p4);
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(p1, p4, pairs);
Assert.assertTrue(opt.isPresent());
Assert.assertTrue(p3 + "is not in LinkedPairs: " + opt.get(), opt.get().contains(p3));
Assert.assertEquals("Expected size = 1; Actual size = " + opt.get().size(), 1, opt.get().size());
}
}