Skip to content

Commit 07e0fa7

Browse files
committed
Add Tests
1 parent bd77390 commit 07e0fa7

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

liquidjava-verifier/src/test/java/liquidjava/rj_language/opt/VCSubstitutionTest.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class VCSubstitutionTest {
1212

1313
@Test
14-
void applyOnceReturnsNullForNullImplication() {
14+
void applyReturnsNullForNullImplication() {
1515
assertNull(VCSubstitution.apply(null));
1616
}
1717

@@ -42,6 +42,44 @@ void substitutesCompoundKnownValue() {
4242
assertSimplifiedVC(result, simplified("y + 1 > y", "∀x:int. x > y"));
4343
}
4444

45+
@Test
46+
void substitutesOnlyWholeVariableReferences() {
47+
VCImplication implication = vc("∀x:int. x == 3", "xx > x");
48+
49+
VCImplication result = VCSubstitution.apply(implication);
50+
51+
assertSimplifiedVC(result, simplified("xx > 3", "∀x:int. xx > x"));
52+
}
53+
54+
@Test
55+
void substitutesEveryOccurrenceInPredicate() {
56+
VCImplication implication = vc("∀x:int. x == 2", "x + x > 0");
57+
58+
VCImplication result = VCSubstitution.apply(implication);
59+
60+
assertSimplifiedVC(result, simplified("2 + 2 > 0", "∀x:int. x + x > 0"));
61+
}
62+
63+
@Test
64+
void preservesRemainingBinderAfterSubstitution() {
65+
VCImplication implication = vc("∀x:int. x == 3", "∀y:int. y > x", "y > 0");
66+
67+
VCImplication result = VCSubstitution.apply(implication);
68+
69+
assertEquals("y", result.getName());
70+
assertEquals("y > 3", result.getRefinement().toString());
71+
assertVC(result.getNext(), "y > 0");
72+
}
73+
74+
@Test
75+
void removesSourceNodeWhenItIsLastInChain() {
76+
VCImplication implication = vc("x > 0", "∀y:int. y == 1");
77+
78+
VCImplication result = VCSubstitution.apply(implication);
79+
80+
assertVC(result, "x > 0");
81+
}
82+
4583
@Test
4684
void usesFirstSubstitutionFoundInChain() {
4785
VCImplication implication = vc("∀x:int. x > 0", "∀y:int. y == 4", "x + y > 0");
@@ -95,6 +133,16 @@ void ignoresNonEqualityBinderRefinement() {
95133
assertVC(result, "x > 3", "x > 0");
96134
}
97135

136+
@Test
137+
void ignoresDerivedBinderEquality() {
138+
VCImplication implication = vc("∀x:int. x + 1 == 3", "x > 0");
139+
140+
VCImplication result = VCSubstitution.apply(implication);
141+
142+
assertNotSame(implication, result);
143+
assertVC(result, "x + 1 == 3", "x > 0");
144+
}
145+
98146
@Test
99147
void ignoresEqualityWithoutBinder() {
100148
VCImplication implication = vc("x == 3", "x > 0");

0 commit comments

Comments
 (0)