92 lines
3.5 KiB
Java
92 lines
3.5 KiB
Java
package unify;
|
|
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
|
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
|
import de.dhbwstuttgart.typeinference.unify.model.MPair;
|
|
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
|
|
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
|
import de.dhbwstuttgart.typeinference.unify.model.Type;
|
|
import de.dhbwstuttgart.typeinference.unifynew.TypeFactory;
|
|
|
|
public class FiniteClosureTest extends FiniteClosure {
|
|
|
|
@Test
|
|
public void testMatch() {
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
Type a = tf.getPlaceholderType("a");
|
|
Type b = tf.getPlaceholderType("b");
|
|
Type c = tf.getPlaceholderType("c");
|
|
|
|
Type A = tf.getSimpleType("A");
|
|
Type B = tf.getSimpleType("B");
|
|
Type C1 = tf.getSimpleType("C", a, b, c);
|
|
Type C2 = tf.getSimpleType("C", a, A, b);
|
|
Type C3 = tf.getSimpleType("C", A, B, A);
|
|
Type D1 = tf.getSimpleType("D", C1, a, b, c);
|
|
Type D2 = tf.getSimpleType("D", C3, A, B, A);
|
|
|
|
System.out.println(match(C2, C1));
|
|
System.out.println(match(C3, C1));
|
|
System.out.println(match(D2, D1));
|
|
Assert.assertFalse(match(C3, C2).isPresent());
|
|
Assert.assertFalse(match(C1, C2).isPresent());
|
|
}
|
|
|
|
@Test
|
|
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")));
|
|
System.out.println("Greater(Collection) = " + fc.greater(tf.getSimpleType("Collection")));
|
|
}
|
|
|
|
@Test
|
|
public void testGrArg() {
|
|
IFiniteClosure fc = new FiniteClosureBuilder().getCollectionExample();
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
System.out.println("\n\n----- GrArg Test -----");
|
|
System.out.println("GrArg(List<T>) = " + fc.grArg(tf.getSimpleType("List", "T")));
|
|
System.out.println("GrArg(? extends List<T>) = " + fc.grArg(tf.getExtendsType(tf.getSimpleType("List", "T"))));
|
|
System.out.println("GrArg(? super List<T>) = " + fc.grArg(tf.getSuperType(tf.getSimpleType("List", "T"))));
|
|
}
|
|
|
|
@Test
|
|
public void testSmaller() {
|
|
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
fcb.add(tf.getSimpleType("Integer"), tf.getSimpleType("Number"));
|
|
IFiniteClosure fc = fcb.getCollectionExample();
|
|
|
|
System.out.println("\n\n----- Smaller Test -----");
|
|
System.out.println("Smaller(List<? extends Number>) = " + fc.smaller(tf.getSimpleType("List", tf.getExtendsType(tf.getSimpleType("Number")))));
|
|
System.out.println("Smaller(List<T>) = " + fc.smaller(tf.getSimpleType("List", "T")));
|
|
System.out.println("Smaller(TreeSet<T>) = " + fc.smaller(tf.getSimpleType("TreeSet", "T")));
|
|
System.out.println("Smaller(Collection) = " + fc.smaller(tf.getSimpleType("Collection")));
|
|
}
|
|
|
|
@Test
|
|
public void testSmArg() {
|
|
IFiniteClosure fc = new FiniteClosureBuilder().getCollectionExample();
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
System.out.println("\n\n----- SmArg Test -----");
|
|
System.out.println("SmArg(List<T>) = " + fc.smArg(tf.getSimpleType("List", "T")));
|
|
System.out.println("SmArg(? extends List<T>) = " + fc.smArg(tf.getExtendsType(tf.getSimpleType("List", "T"))));
|
|
System.out.println("SmArg(? super List<T>) = " + fc.smArg(tf.getSuperType(tf.getSimpleType("List", "T"))));
|
|
}
|
|
|
|
@Test
|
|
public void testGetGenericType() {
|
|
|
|
// TODO
|
|
}
|
|
}
|