Java, typeres: split incorporation tests

This commit is contained in:
Bendegúz Nagy
2017-07-24 19:36:30 +02:00
parent db6dc4d5bc
commit 6b335b1a25

View File

@ -30,8 +30,10 @@ public class TypeInferenceTest {
private JavaTypeDefinition integer = JavaTypeDefinition.forClass(Integer.class);
private JavaTypeDefinition primitiveInt = JavaTypeDefinition.forClass(int.class);
private JavaTypeDefinition generic = JavaTypeDefinition.forClass(Map.class, number, integer);
private Variable a = new Variable();
private Variable b = new Variable();
private Variable alpha = new Variable();
private Variable beta = new Variable();
JavaTypeDefinition s = JavaTypeDefinition.forClass(int.class);
JavaTypeDefinition t = JavaTypeDefinition.forClass(double.class);
@Test
public void testEqualityReduceProperVsProper() {
@ -47,22 +49,22 @@ public class TypeInferenceTest {
public void testEqualityReduceVariableVsNotPrimitive() {
// Otherwise, if S is an inference variable, α, and T is not a primitive type, the constraint reduces to
// the bound α = T.
List<BoundOrConstraint> result = new Constraint(a, number, EQUALITY).reduce();
List<BoundOrConstraint> result = new Constraint(alpha, number, EQUALITY).reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), a, number, EQUALITY, Bound.class);
testBoundOrConstraint(result.get(0), alpha, number, EQUALITY, Bound.class);
}
@Test
public void testEqualityReduceNotPrimitiveVsVariable() {
// Otherwise, if T is an inference variable, α, and S is not a primitive type, the constraint reduces
// to the bound S = α.
List<BoundOrConstraint> result = new Constraint(number, a, EQUALITY).reduce();
List<BoundOrConstraint> result = new Constraint(number, alpha, EQUALITY).reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), number, a, EQUALITY, Bound.class);
testBoundOrConstraint(result.get(0), number, alpha, EQUALITY, Bound.class);
result = new Constraint(a, b, EQUALITY).reduce();
result = new Constraint(alpha, beta, EQUALITY).reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), a, b, EQUALITY, Bound.class);
testBoundOrConstraint(result.get(0), alpha, beta, EQUALITY, Bound.class);
}
@Test
@ -80,7 +82,8 @@ public class TypeInferenceTest {
public void testEqualityReduceArrayTypes() {
// Otherwise, if S and T are array types, S'[] and T'[], the constraint reduces to S' = T'.
List<BoundOrConstraint> result = new Constraint(JavaTypeDefinition.forClass(Number[].class),
JavaTypeDefinition.forClass(Integer[].class), EQUALITY).reduce();
JavaTypeDefinition.forClass(Integer[].class), EQUALITY)
.reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), number, integer, EQUALITY, Constraint.class);
}
@ -105,21 +108,21 @@ public class TypeInferenceTest {
@Test
public void testSubtypeReduceVariableVsAny() {
// Otherwise, if S is an inference variable, α, the constraint reduces to the bound α <: T.
List<BoundOrConstraint> result = new Constraint(a, integer, SUBTYPE).reduce();
List<BoundOrConstraint> result = new Constraint(alpha, integer, SUBTYPE).reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), a, integer, SUBTYPE, Bound.class);
testBoundOrConstraint(result.get(0), alpha, integer, SUBTYPE, Bound.class);
}
@Test
public void testSubtypeReduceAnyVsVariable() {
// Otherwise, if T is an inference variable, α, the constraint reduces to the bound S <: α.
List<BoundOrConstraint> result = new Constraint(integer, a, SUBTYPE).reduce();
List<BoundOrConstraint> result = new Constraint(integer, alpha, SUBTYPE).reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), integer, a, SUBTYPE, Bound.class);
testBoundOrConstraint(result.get(0), integer, alpha, SUBTYPE, Bound.class);
result = new Constraint(a, b, SUBTYPE).reduce();
result = new Constraint(alpha, beta, SUBTYPE).reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), a, b, SUBTYPE, Bound.class);
testBoundOrConstraint(result.get(0), alpha, beta, SUBTYPE, Bound.class);
}
@ -167,13 +170,13 @@ public class TypeInferenceTest {
@Test
public void testLooseInvocationAnythingElse() {
// Otherwise, the constraint reduces to S<:T.
List<BoundOrConstraint> result = new Constraint(number, a, LOOSE_INVOCATION).reduce();
List<BoundOrConstraint> result = new Constraint(number, alpha, LOOSE_INVOCATION).reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), number, a, SUBTYPE, Constraint.class);
testBoundOrConstraint(result.get(0), number, alpha, SUBTYPE, Constraint.class);
result = new Constraint(a, number, LOOSE_INVOCATION).reduce();
result = new Constraint(alpha, number, LOOSE_INVOCATION).reduce();
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), a, number, SUBTYPE, Constraint.class);
testBoundOrConstraint(result.get(0), alpha, number, SUBTYPE, Constraint.class);
}
@Test
@ -198,14 +201,8 @@ public class TypeInferenceTest {
}
@Test
public void testIncorporation() {
public void testIncorporationEqualityAndEquality() {
List<Constraint> result;
List<Bound> current = new ArrayList<>();
List<Bound> newBounds = new ArrayList<>();
JavaTypeDefinition s = JavaTypeDefinition.forClass(int.class);
JavaTypeDefinition t = JavaTypeDefinition.forClass(double.class);
Variable alpha = a;
// ### Original rule 1. : α = S and α = T imply S = T
result = incorporationResult(new Bound(alpha, s, EQUALITY), new Bound(alpha, t, EQUALITY));
@ -226,7 +223,11 @@ public class TypeInferenceTest {
result = incorporationResult(new Bound(s, alpha, EQUALITY), new Bound(t, alpha, EQUALITY));
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), s, t, EQUALITY, Constraint.class);
}
@Test
public void testIncorporationEqualityAndSubtypeLeftVariable() {
List<Constraint> result;
// ### Original rule 2. : α = S and α <: T imply S <: T
result = incorporationResult(new Bound(alpha, s, EQUALITY), new Bound(alpha, t, SUBTYPE));
@ -247,7 +248,11 @@ public class TypeInferenceTest {
result = incorporationResult(new Bound(alpha, t, SUBTYPE), new Bound(s, alpha, EQUALITY));
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), s, t, SUBTYPE, Constraint.class);
}
@Test
public void testIncorporationEqualityAndSubtypeRightVariable() {
List<Constraint> result;
// ### Original rule 3. : α = S and T <: α imply T <: S
result = incorporationResult(new Bound(alpha, s, EQUALITY), new Bound(t, alpha, SUBTYPE));
@ -268,8 +273,12 @@ public class TypeInferenceTest {
result = incorporationResult(new Bound(t, alpha, SUBTYPE), new Bound(s, alpha, EQUALITY));
assertEquals(result.size(), 1);
testBoundOrConstraint(result.get(0), t, s, SUBTYPE, Constraint.class);
}
@Test
public void testIncorporationSubtypeAndSubtype() {
List<Constraint> result;
// ### Original rule 4. : S <: α and α <: T imply S <: T
result = incorporationResult(new Bound(s, alpha, EQUALITY), new Bound(alpha, t, SUBTYPE));
assertEquals(result.size(), 1);