Skip to content

Commit 84f9727

Browse files
committed
Add Tests
1 parent 11be88b commit 84f9727

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,35 @@ void leavesDivisionAndModuloByZeroUnchanged() {
4343
assertUnchanged("4 % 0 == 0");
4444
}
4545

46+
@Test
47+
void leavesRealDivisionAndModuloByZeroUnchanged() {
48+
assertUnchanged("4.0 / 0.0 == 0.0");
49+
assertUnchanged("4.0 % 0.0 == 0.0");
50+
}
51+
4652
@Test
4753
void foldsBooleanBinaryExpressions() {
4854
assertFolded("true && false", "false");
4955
assertFolded("false --> true", "true");
5056
assertFolded("true != false", "true");
5157
}
5258

59+
@Test
60+
void foldsBooleanSubexpressionsInsideLargerExpression() {
61+
assertFolded("true && false || ok", "false || ok");
62+
}
63+
64+
@Test
65+
void foldsNestedConstantsInsideLargerExpression() {
66+
assertFolded("x > 1 + 2", "x > 3");
67+
assertFolded("x + 1 + 2 > 4", "x + 3 > 4");
68+
}
69+
70+
@Test
71+
void foldsPartialComparisonsWithoutDroppingSymbolicTerms() {
72+
assertFolded("1 + 2 < x + 4", "3 < x + 4");
73+
}
74+
5375
@Test
5476
void foldsUnaryExpressions() {
5577
assertFolded("!true", "false");
@@ -63,6 +85,11 @@ void foldsIteExpressions() {
6385
assertFolded("cond ? b : b", "b");
6486
}
6587

88+
@Test
89+
void foldsIteBranchesBeforeComparingThem() {
90+
assertFolded("cond ? 1 + 2 : 3", "3");
91+
}
92+
6693
@Test
6794
void foldsAdjacentIntegerConstants() {
6895
assertFolded("x + 1 - 2", "x - 1");
@@ -89,6 +116,19 @@ void foldsResolvedEnumLiterals() {
89116
assertSimplifiedVC(result, simplified("true", "Config.LIMIT == 3"));
90117
}
91118

119+
@Test
120+
void foldsResolvedEnumLiteralsInsideLargerExpression() {
121+
Enum limit = new Enum("Config", "LIMIT");
122+
limit.setResolvedLiteral(new LiteralInt(3));
123+
BinaryExpression arithmetic = new BinaryExpression(limit, "+", new LiteralInt(2));
124+
VCImplication implication = new VCImplication(
125+
new Predicate(new BinaryExpression(arithmetic, "==", new LiteralInt(5))));
126+
127+
VCImplication result = VCFolding.apply(implication);
128+
129+
assertSimplifiedVC(result, simplified("true", "Config.LIMIT + 2 == 5"));
130+
}
131+
92132
@Test
93133
void preservesOriginFromExistingSimplifiedImplication() {
94134
VCImplication substituted = VCSubstitution.apply(vc("∀x:int. x == 1", "x + 1 + 2 > 0"));

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ void simplifyOnceAppliesSubstitutionBeforeFolding() {
3030
assertSimplifiedVC(result, simplified("1 + 2 > 2", "∀x:int. x > 2"));
3131
}
3232

33+
@Test
34+
void simplifyOnceDoesNotFoldAfterSubstitutionInSameStep() {
35+
VCImplication implication = vc("∀x:int. x == 1 + 2", "x == 3");
36+
37+
VCImplication result = VCSimplification.simplifyOnce(implication);
38+
39+
assertSimplifiedVC(result, simplified("1 + 2 == 3", "∀x:int. x == 3"));
40+
}
41+
3342
@Test
3443
void simplifyOnceAppliesFoldingWhenNoSubstitutionIsAvailable() {
3544
VCImplication implication = vc("1 + 2 > 2");
@@ -57,6 +66,24 @@ void simplifyAppliesMultipleSubstitutionsBeforeReachingFixedPoint() {
5766
assertSimplifiedVC(result, simplified("true", "∀y:int. y > x"));
5867
}
5968

69+
@Test
70+
void simplifyAppliesLongSubstitutionChainBeforeReachingFixedPoint() {
71+
VCImplication implication = vc("∀x:int. x == 1", "∀y:int. y == x + 1", "∀z:int. z == y + 1", "z == 3");
72+
73+
VCImplication result = VCSimplification.simplifyToFixedPoint(implication);
74+
75+
assertSimplifiedVC(result, simplified("true", "∀z:int. z == 3"));
76+
}
77+
78+
@Test
79+
void simplifyCombinesSubstitutionAndNestedFoldingAcrossFixedPoint() {
80+
VCImplication implication = vc("∀x:int. x == 1", "∀y:int. y == x + 2", "y - 1 == 2");
81+
82+
VCImplication result = VCSimplification.simplifyToFixedPoint(implication);
83+
84+
assertSimplifiedVC(result, simplified("true", "∀y:int. y - 1 == 2"));
85+
}
86+
6087
@Test
6188
void simplifyLeavesUnchangedVcAsPlainPredicates() {
6289
VCImplication implication = vc("x > 0", "y > x");

0 commit comments

Comments
 (0)