Change tests

This commit is contained in:
Victorious3 2023-03-28 16:40:06 +02:00
parent 1ad5540500
commit f7b60214fa
3 changed files with 22 additions and 17 deletions

View File

@ -647,20 +647,23 @@ public class ASTToTargetAST {
}
void equalizeTypeVariables(Set<ResultPair<?, ?>> input, Map<TypePlaceholder, TypePlaceholder> equality) {
System.out.println(input);
for (var pair : new HashSet<>(input)) {
if (pair instanceof PairTPHsmallerTPH ptph) {
System.out.println(pair + " " + ptph.left.getVariance() + " " + ptph.right.getVariance());
if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) {
addToEquality(equality, ptph.left, ptph.right);
input.remove(ptph);
for (var pair2 : new HashSet<>(input)) {
if (pair2 instanceof PairTPHsmallerTPH ptph2 && ptph2.right.equals(ptph.left)) {
input.remove(pair2);
addToPairs(input, new PairTPHsmallerTPH(ptph2.left, ptph.right));
for (var pair2 : new HashSet<>(simplifiedConstraints)) {
if (pair2.right.equals(ptph.left)) {
simplifiedConstraints.remove(pair2);
simplifiedConstraints.add(new PairTPHsmallerTPH(pair2.left, ptph.right));
}
}
}
}
}
System.out.println(input);
}
void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set<TypePlaceholder> tphs, Map<TypePlaceholder, TypePlaceholder> equality) {

View File

@ -18,14 +18,14 @@ public class GenericsResult {
public Set<ResultPair<?, ?>> get(ClassOrInterface clazz) {
var generics = this.sigma.computedGenericsOfClasses.get(clazz);
if (generics == null) return Set.of();
return generics.txGenerics();
return generics.javaGenerics();
}
// TODO Compute generics if not present?
public Set<ResultPair<?, ?>> get(Method method) {
var generics = this.sigma.computedGenericsOfMethods.get(method);
if (generics == null) return Set.of();
return generics.txGenerics();
return generics.javaGenerics();
}
public BoundsList getBounds(RefTypeOrTPHOrWildcardOrGeneric type, ClassOrInterface clazz) {

View File

@ -127,26 +127,22 @@ public class TestGenerics {
assertEquals(R, RChain);
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
var OChain = new BoundsList(new Bound(true, TypePlaceholder.of("AB")), new Bound(true, ASTToTargetAST.OBJECT));
assertEquals(O, OChain);
var AB = generics.getBounds(id.getReturnType(), result.clazz, id);
assertEquals(O, AB);
assertEquals(AB, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
var SChain = new BoundsList(new Bound(true, TypePlaceholder.of("R")), new Bound(false, ASTToTargetAST.OBJECT));
assertEquals(S, SChain);
assertEquals(S, RChain);
assertEquals(generics.getBounds(setA.getReturnType(), result.clazz, setA), RChain);
var X = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
var XChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
var YChain = new BoundsList(new Bound(true, TypePlaceholder.of("Y")), new Bound(true, ASTToTargetAST.OBJECT));
assertEquals(X, XChain);
assertEquals(Y, YChain);
assertEquals(Y, X);
}
@Test
@Ignore("Not implemented")
public void testLocalVarLambda() throws Exception {
var result = computeGenerics("TestLocalVarLambda.jav");
// TODO Generics of lambdas
@ -221,9 +217,10 @@ public class TestGenerics {
var Q = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
assertEquals(Q, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
System.out.println(otherMethod.getReturnType());
var DYX2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod);
assertEquals(DYX, DYX2);
assertEquals(DYX2, DYXChain);
assertEquals(DYX, generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod));
}
@Test
@ -247,7 +244,7 @@ public class TestGenerics {
var AA = generics.getBounds(m.getReturnType(), result.clazz, m);
var AC = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
assertEquals(AC, new BoundsList(new Bound(true, TypePlaceholder.of("AD")), new Bound(true, ASTToTargetAST.OBJECT)));
assertEquals(AC, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
var AH = generics.getBounds(m2.getReturnType(), result.clazz, m2);
var AL = generics.getBounds(m2.getParameterList().getParameterAt(0).getType(), result.clazz, m2);
@ -298,9 +295,9 @@ public class TestGenerics {
}
@Test
@Ignore("main changes in between runs")
public void testTwoArgs2() throws Exception {
var result = computeGenerics("TestTwoArgs2.jav");
// TODO Test generics
}
@Test
@ -327,6 +324,7 @@ public class TestGenerics {
public void testVector() throws Exception {
var result = computeGenerics("TestVector.jav");
var m = result.findMethod("m");
var id = result.findMethod("id");
var generics = result.genericsResults.get(0);
var par1 = generics.resolve(m.getParameterList().getParameterAt(0).getType());
@ -334,8 +332,12 @@ public class TestGenerics {
var S = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, m);
var ACM = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, m);
assertEquals(S, new BoundsList(new Bound(true, TypePlaceholder.of("V")), new Bound(true, TypePlaceholder.of("ACM")), new Bound(true, ASTToTargetAST.OBJECT)));
assertEquals(S, new BoundsList(new Bound(true, TypePlaceholder.of("V")), new Bound(true, ASTToTargetAST.OBJECT)));
assertEquals(ACM, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
var Y = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
assertEquals(Y, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
assertEquals(Y, generics.getBounds(id.getReturnType(), result.clazz, id));
}
@Test