|
11 | 11 | class VCSubstitutionTest { |
12 | 12 |
|
13 | 13 | @Test |
14 | | - void applyOnceReturnsNullForNullImplication() { |
| 14 | + void applyReturnsNullForNullImplication() { |
15 | 15 | assertNull(VCSubstitution.apply(null)); |
16 | 16 | } |
17 | 17 |
|
@@ -42,6 +42,44 @@ void substitutesCompoundKnownValue() { |
42 | 42 | assertSimplifiedVC(result, simplified("y + 1 > y", "∀x:int. x > y")); |
43 | 43 | } |
44 | 44 |
|
| 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 | + |
45 | 83 | @Test |
46 | 84 | void usesFirstSubstitutionFoundInChain() { |
47 | 85 | VCImplication implication = vc("∀x:int. x > 0", "∀y:int. y == 4", "x + y > 0"); |
@@ -95,6 +133,16 @@ void ignoresNonEqualityBinderRefinement() { |
95 | 133 | assertVC(result, "x > 3", "x > 0"); |
96 | 134 | } |
97 | 135 |
|
| 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 | + |
98 | 146 | @Test |
99 | 147 | void ignoresEqualityWithoutBinder() { |
100 | 148 | VCImplication implication = vc("x == 3", "x > 0"); |
|
0 commit comments