JavaPatternMatching/test/unify/FiniteClosureTest.java

91 lines
3.5 KiB
Java
Raw Normal View History

2015-11-07 15:21:17 +00:00
package unify;
2016-03-20 14:09:12 +00:00
import org.junit.Assert;
2015-11-07 15:21:17 +00:00
import org.junit.Test;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
2015-12-26 23:29:23 +00:00
import de.dhbwstuttgart.typeinference.unify.model.MPair;
2016-03-22 14:13:51 +00:00
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
2016-03-20 14:09:12 +00:00
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
2016-03-22 14:13:51 +00:00
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
2015-11-07 15:21:17 +00:00
2016-03-20 14:09:12 +00:00
public class FiniteClosureTest extends FiniteClosure {
@Test
public void testMatch() {
TypeFactory tf = new TypeFactory();
2016-03-22 14:13:51 +00:00
UnifyType a = tf.getPlaceholderType("a");
UnifyType b = tf.getPlaceholderType("b");
UnifyType c = tf.getPlaceholderType("c");
2016-03-20 14:09:12 +00:00
2016-03-22 14:13:51 +00:00
UnifyType A = tf.getSimpleType("A");
UnifyType B = tf.getSimpleType("B");
UnifyType C1 = tf.getSimpleType("C", a, b, c);
UnifyType C2 = tf.getSimpleType("C", a, A, b);
UnifyType C3 = tf.getSimpleType("C", A, B, A);
UnifyType D1 = tf.getSimpleType("D", C1, a, b, c);
UnifyType D2 = tf.getSimpleType("D", C3, A, B, A);
2016-03-20 14:09:12 +00:00
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());
}
2015-11-07 15:21:17 +00:00
@Test
public void testGreater() {
IFiniteClosure fc = new FiniteClosureBuilder().getCollectionExample();
TypeFactory tf = new TypeFactory();
2015-11-07 19:37:29 +00:00
2015-11-07 15:21:17 +00:00
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();
2015-11-07 15:21:17 +00:00
TypeFactory tf = new TypeFactory();
fcb.add(tf.getSimpleType("Integer"), tf.getSimpleType("Number"));
IFiniteClosure fc = fcb.getCollectionExample();
2015-11-07 15:21:17 +00:00
System.out.println("\n\n----- Smaller Test -----");
System.out.println("Smaller(List<? extends Number>) = " + fc.smaller(tf.getSimpleType("List", tf.getExtendsType(tf.getSimpleType("Number")))));
2015-11-07 15:21:17 +00:00
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"))));
}
2016-03-13 22:01:28 +00:00
@Test
public void testGetGenericType() {
// TODO
}
2015-11-07 15:21:17 +00:00
}