@@ -26,7 +26,7 @@ void foldsIntegerArithmeticAndComparisons() {
2626 VCImplication implication = vc ("1 + 2 == 3" );
2727
2828 assertSimplificationSteps (VCFolding ::apply , implication , chain (expect ("3 == 3" , "1 + 2 == 3" )),
29- chain (expect ("true" , "1 + 2 == 3" )));
29+ chain (expect ("true" , "3 == 3" )));
3030 assertSimplificationSteps (VCFolding ::apply , vc ("4 > 7" ), chain (expect ("false" , "4 > 7" )));
3131 }
3232
@@ -36,9 +36,9 @@ void foldsRealAndMixedNumericExpressions() {
3636 VCImplication mixedArithmetic = vc ("2 + 0.5 > 2" );
3737
3838 assertSimplificationSteps (VCFolding ::apply , realArithmetic , chain (expect ("3.5 == 3.5" , "1.5 + 2.0 == 3.5" )),
39- chain (expect ("true" , "1.5 + 2.0 == 3.5" )));
39+ chain (expect ("true" , "3.5 == 3.5" )));
4040 assertSimplificationSteps (VCFolding ::apply , mixedArithmetic , chain (expect ("2.5 > 2" , "2 + 0.5 > 2" )),
41- chain (expect ("true" , "2 + 0 .5 > 2" )));
41+ chain (expect ("true" , "2.5 > 2" )));
4242 }
4343
4444 @ Test
@@ -55,6 +55,27 @@ void leavesRealDivisionAndModuloByZeroUnchanged() {
5555 chain (expect ("4.0 % 0.0 == 0.0" , "4.0 % 0.0 == 0.0" )));
5656 }
5757
58+ @ Test
59+ void foldsIntegerDivisionTowardZeroForNegativeResults () {
60+ VCImplication implication = vc ("(2 - 7) / 2 == -2" );
61+
62+ assertSimplificationSteps (VCFolding ::apply , implication ,
63+ chain (expect ("(2 - 7) / 2 == -2" , "(2 - 7) / 2 == -2" )),
64+ chain (expect ("-5 / 2 == -2" , "(2 - 7) / 2 == -2" )), chain (expect ("-2 == -2" , "-5 / 2 == -2" )),
65+ chain (expect ("-2 == -2" , "-2 == -2" )), chain (expect ("true" , "-2 == -2" )));
66+ }
67+
68+ @ Test
69+ void foldsIntegerModuloWithJavaSignedRemainder () {
70+ VCImplication negativeDividend = vc ("-5 % 2 < 0" );
71+ VCImplication negativeDivisor = vc ("5 % -2 > 0" );
72+
73+ assertSimplificationSteps (VCFolding ::apply , negativeDividend , chain (expect ("-5 % 2 < 0" , "-5 % 2 < 0" )),
74+ chain (expect ("-1 < 0" , "-5 % 2 < 0" )), chain (expect ("true" , "-1 < 0" )));
75+ assertSimplificationSteps (VCFolding ::apply , negativeDivisor , chain (expect ("5 % -2 > 0" , "5 % -2 > 0" )),
76+ chain (expect ("1 > 0" , "5 % -2 > 0" )), chain (expect ("true" , "1 > 0" )));
77+ }
78+
5879 @ Test
5980 void foldsBooleanBinaryExpressions () {
6081 assertSimplificationSteps (VCFolding ::apply , vc ("true && false" ), chain (expect ("false" , "true && false" )));
@@ -100,7 +121,7 @@ void foldsIteBranchesBeforeComparingThem() {
100121 VCImplication implication = vc ("cond ? 1 + 2 : 3" );
101122
102123 assertSimplificationSteps (VCFolding ::apply , implication , chain (expect ("cond ? 3 : 3" , "cond ? 1 + 2 : 3" )),
103- chain (expect ("3" , "cond ? 1 + 2 : 3" )));
124+ chain (expect ("3" , "cond ? 3 : 3" )));
104125 }
105126
106127 @ Test
@@ -127,7 +148,7 @@ void foldsResolvedEnumLiterals() {
127148 new Predicate (new BinaryExpression (limit , "==" , new LiteralInt (3 ))));
128149
129150 assertSimplificationSteps (VCFolding ::apply , implication , chain (expect ("3 == 3" , "Config.LIMIT == 3" )),
130- chain (expect ("true" , "Config.LIMIT == 3" )));
151+ chain (expect ("true" , "3 == 3" )));
131152 }
132153
133154 @ Test
@@ -139,15 +160,15 @@ void foldsResolvedEnumLiteralsInsideLargerExpression() {
139160 new Predicate (new BinaryExpression (arithmetic , "==" , new LiteralInt (5 ))));
140161
141162 assertSimplificationSteps (VCFolding ::apply , implication , chain (expect ("3 + 2 == 5" , "Config.LIMIT + 2 == 5" )),
142- chain (expect ("5 == 5" , "Config.LIMIT + 2 == 5" )), chain (expect ("true" , "Config.LIMIT + 2 == 5" )));
163+ chain (expect ("5 == 5" , "3 + 2 == 5" )), chain (expect ("true" , "5 == 5" )));
143164 }
144165
145166 @ Test
146- void preservesOriginFromExistingSimplifiedImplication () {
167+ void recordsCurrentImplicationAsOriginWhenFoldingExistingSimplifiedImplication () {
147168 VCImplication substituted = VCSubstitution .apply (vc ("∀x:int. x == 1" , "x + 1 + 2 > 0" ));
148169
149- assertSimplificationSteps (VCFolding ::apply , substituted , chain (expect ("2 + 2 > 0" , "∀x:int. x + 1 + 2 > 0" )),
150- chain (expect ("4 > 0" , "∀x:int. x + 1 + 2 > 0" )), chain (expect ("true" , "∀x:int. x + 1 + 2 > 0" )));
170+ assertSimplificationSteps (VCFolding ::apply , substituted , chain (expect ("2 + 2 > 0" , "1 + 1 + 2 > 0" )),
171+ chain (expect ("4 > 0" , "2 + 2 > 0" )), chain (expect ("true" , "4 > 0" )));
151172 }
152173
153174 @ Test
@@ -169,13 +190,13 @@ void recordsOriginWhenFoldingLaterImplication() {
169190 chain (expect ("x > 0" , "x > 0" ), expect ("3 > 0" , "1 + 2 > 0" )));
170191
171192 SimplifiedVCImplication simplifiedNext = assertInstanceOf (SimplifiedVCImplication .class , result .getNext ());
172- assertEquals ("1 + 2 > 0" , simplifiedNext .getOrigin ().getRefinement ().toString ());
193+ assertEquals ("1 + 2 > 0" , simplifiedNext .getOrigin ().getRefinement ().getExpression (). toDisplayString ());
173194
174195 result = assertSimplificationSteps (VCFolding ::apply , result ,
175- chain (expect ("x > 0" , "x > 0" ), expect ("true" , "1 + 2 > 0" )));
196+ chain (expect ("x > 0" , "x > 0" ), expect ("true" , "3 > 0" )));
176197
177198 simplifiedNext = assertInstanceOf (SimplifiedVCImplication .class , result .getNext ());
178- assertEquals ("1 + 2 > 0" , simplifiedNext .getOrigin ().getRefinement ().toString ());
199+ assertEquals ("3 > 0" , simplifiedNext .getOrigin ().getRefinement ().getExpression (). toDisplayString ());
179200 }
180201
181202}
0 commit comments