modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java

This commit is contained in:
AluAli 2020-12-04 14:59:09 +01:00
parent d06c6abb5a
commit c2f0368d2e

View File

@ -3,7 +3,6 @@ package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.*;
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import junit.framework.TestCase;
import java.util.ArrayList;
@ -12,31 +11,27 @@ import java.util.List;
public class FamilyOfGeneratedGenericsTest extends TestCase {
/*
public void testIdentityMethod(){
*/
/*
/*
Example method:
A id(B i) return i;
gives constraint: B <. A, which is a method constraint
*//*
*/
List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS));
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
tphPositions.put("A", PositionFinder.Position.METHOD);
tphPositions.put("B", PositionFinder.Position.METHOD);
PairTphMethod<PositionFinder.Position, String> meth1 = new PairTphMethod<PositionFinder.Position, String>(PositionFinder.Position.METHOD, "m1");
tphPositions.put("A", meth1);
tphPositions.put("B", meth1);
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
assertTrue(classConstraints.isEmpty());
*/
/*
/*
MethodConstraints should be the same as the input constraint
*//*
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, tphPositions);
assertTrue(methodConstraints.size() == 1);
assertTrue(methodConstraints.get(0).getLeft().equals("B"));
@ -44,8 +39,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
public void testClassField(){
*/
/*
*//*
class Example{
A f;
B fReturn(){
@ -55,7 +49,6 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
gives constraint: A <. B, which is a class constraint
*//*
List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
@ -63,11 +56,9 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
tphPositions.put("A", PositionFinder.Position.FIELD);
tphPositions.put("B", PositionFinder.Position.METHOD);
*/
/*
*//*
ClassConstraints should not be the same as the input constraint
*//*
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints);
assertTrue(classConstraints.size() == 2);
@ -76,8 +67,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
public void testSecondLineOfClassConstraints() {
*/
/*
*//*
class Example() {
A a;
B b = a;
@ -93,7 +83,6 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
*//*
List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
inputConstraints.add(new TPHConstraint("F", "C", TPHConstraint.Relation.EXTENDS));
@ -117,8 +106,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
public void testTPHsAndGenerics() {
*/
/*
*//*
class TPHsAndGenerics {
Fun1<A,B> id = x -> x;
C id2 (D x) {
@ -134,7 +122,6 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
*//*
List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS));
inputConstraints.add(new TPHConstraint("B","C", TPHConstraint.Relation.EXTENDS));
@ -161,8 +148,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 3);
}
*/
}*/
public void testPositionConverter() {
@ -171,16 +157,22 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
allTphsOld.put("A", true);
allTphsOld.put("B", false);
MethodAndTPH m1 = new MethodAndTPH("m1");
listOfMethodsAndTphs.add(new MethodAndTPH("bla"));
listOfMethodsAndTphs.add(new MethodAndTPH("blubb"));
m1.getTphs().add("A");
MethodAndTPH bla = new MethodAndTPH("bla");
MethodAndTPH blubb = new MethodAndTPH("blubb");
blubb.getTphs().add("A");
listOfMethodsAndTphs.add(bla);
listOfMethodsAndTphs.add(blubb);
listOfMethodsAndTphs.add(m1);
HashMap<String, PairTphMethod<PositionFinder.Position, String>> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs);
System.out.println(allTphsNew);
//was tun wenn zwei (oder mehr) Methoden gleiches TPH enthalten?
//ist dies möglich oder werden die TPHs immer verschieden initialisiert und dann erst am Ende gemappt?
//überarbeiten oder lassen?
assertTrue(allTphsNew.get("A").fst.equals(PositionFinder.Position.METHOD));
assertTrue(allTphsNew.get("B").fst.equals(PositionFinder.Position.FIELD));