forked from JavaTX/JavaCompilerCore
smarg and grarg tests
This commit is contained in:
parent
e49c2a35de
commit
4765c2afe0
60
test/unify/FiniteClosureBuilder.java
Normal file
60
test/unify/FiniteClosureBuilder.java
Normal file
@ -0,0 +1,60 @@
|
||||
package unify;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typinference.unify.model.MPair;
|
||||
import de.dhbwstuttgart.typinference.unify.model.MPair.PairOperator;
|
||||
import de.dhbwstuttgart.typinference.unify.model.Type;
|
||||
|
||||
public class FiniteClosureBuilder {
|
||||
|
||||
private Set<MPair> pairs = new HashSet<>();
|
||||
|
||||
public void add(Type sub, Type sup) {
|
||||
pairs.add(new MPair(sub, sup, PairOperator.SMALLER));
|
||||
}
|
||||
|
||||
public IFiniteClosure getFiniteClosure() {
|
||||
FiniteClosure fc = new FiniteClosure(pairs);
|
||||
pairs = new HashSet<>();
|
||||
return fc;
|
||||
}
|
||||
|
||||
public IFiniteClosure getCollectionExample() {
|
||||
TypeFactory tf = new TypeFactory();
|
||||
|
||||
Type collection = tf.getSimpleType("Collection");
|
||||
Type set = tf.getSimpleType("Set", "T");
|
||||
Type sortedSet = tf.getSimpleType("Set", "K");
|
||||
Type TreeSet = tf.getSimpleType("TreeSet", "T");
|
||||
Type hashSet = tf.getSimpleType("HashSet", "Z");
|
||||
Type linkedHashSet = tf.getSimpleType("LinkedHashSet", "T");
|
||||
Type queue = tf.getSimpleType("Queue", "U");
|
||||
Type deque = tf.getSimpleType("Deque", "U");
|
||||
Type linkedList = tf.getSimpleType("LinkedList", "U");
|
||||
Type list = tf.getSimpleType("List", "T");
|
||||
Type vector = tf.getSimpleType("Vector", "T");
|
||||
Type stack = tf.getSimpleType("Stack", "T");
|
||||
Type arrayList = tf.getSimpleType("ArrayList", "T");
|
||||
|
||||
add(set, collection);
|
||||
add(sortedSet, set);
|
||||
add(TreeSet, sortedSet);
|
||||
add(hashSet, set);
|
||||
add(linkedHashSet, set);
|
||||
|
||||
add(queue, collection);
|
||||
add(deque, queue);
|
||||
add(linkedList, deque);
|
||||
add(list, collection);
|
||||
add(linkedList, list);
|
||||
add(vector, list);
|
||||
add(arrayList, list);
|
||||
add(stack, vector);
|
||||
|
||||
return getFiniteClosure();
|
||||
}
|
||||
}
|
53
test/unify/FiniteClosureTest.java
Normal file
53
test/unify/FiniteClosureTest.java
Normal file
@ -0,0 +1,53 @@
|
||||
package unify;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typinference.unify.model.Type;
|
||||
|
||||
public class FiniteClosureTest {
|
||||
|
||||
@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() {
|
||||
IFiniteClosure fc = new FiniteClosureBuilder().getCollectionExample();
|
||||
TypeFactory tf = new TypeFactory();
|
||||
|
||||
System.out.println("\n\n----- Smaller Test -----");
|
||||
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"))));
|
||||
}
|
||||
}
|
37
test/unify/TypeFactory.java
Normal file
37
test/unify/TypeFactory.java
Normal file
@ -0,0 +1,37 @@
|
||||
package unify;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.typinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typinference.unify.model.SimpleType;
|
||||
import de.dhbwstuttgart.typinference.unify.model.SuperType;
|
||||
import de.dhbwstuttgart.typinference.unify.model.Type;
|
||||
|
||||
public class TypeFactory {
|
||||
|
||||
public ExtendsType getExtendsType(Type extendedType) {
|
||||
return new ExtendsType(extendedType);
|
||||
}
|
||||
|
||||
public SuperType getSuperType(Type superedType) {
|
||||
return new SuperType(superedType);
|
||||
}
|
||||
|
||||
public SimpleType getSimpleType(String name) {
|
||||
return new SimpleType(name);
|
||||
}
|
||||
|
||||
public SimpleType getSimpleType(String name, Type... typeParams) {
|
||||
return new SimpleType(name, typeParams);
|
||||
}
|
||||
|
||||
public SimpleType getSimpleType(String name, String... typeParams) {
|
||||
return new SimpleType(name, Arrays.stream(typeParams).map(x -> getPlaceholderType(x)).collect(Collectors.toList()).toArray(new Type[0]));
|
||||
}
|
||||
|
||||
public PlaceholderType getPlaceholderType(String name) {
|
||||
return new PlaceholderType(name);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user