11package liquidjava .rj_language .opt ;
22
3- import static liquidjava .utils .VCTestUtils .assertSimplificationSteps ;
4- import static liquidjava .utils .VCTestUtils .vc ;
3+ import static liquidjava .utils .VCTestUtils .*;
54import static org .junit .jupiter .api .Assertions .assertEquals ;
65import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
76import static org .junit .jupiter .api .Assertions .assertNull ;
@@ -26,88 +25,98 @@ void applyReturnsNullForNullImplication() {
2625 void foldsIntegerArithmeticAndComparisons () {
2726 VCImplication implication = vc ("1 + 2 == 3" );
2827
29- assertSimplificationSteps (VCFolding ::apply , implication , "3 == 3" , "true" );
30- assertSimplificationSteps (VCFolding ::apply , vc ("4 > 7" ), "false" );
28+ assertSimplificationSteps (VCFolding ::apply , implication , chain (expect ("3 == 3" , "1 + 2 == 3" )),
29+ chain (expect ("true" , "1 + 2 == 3" )));
30+ assertSimplificationSteps (VCFolding ::apply , vc ("4 > 7" ), chain (expect ("false" , "4 > 7" )));
3131 }
3232
3333 @ Test
3434 void foldsRealAndMixedNumericExpressions () {
3535 VCImplication realArithmetic = vc ("1.5 + 2.0 == 3.5" );
3636 VCImplication mixedArithmetic = vc ("2 + 0.5 > 2" );
3737
38- assertSimplificationSteps (VCFolding ::apply , realArithmetic , "3.5 == 3.5" , "true" );
39- assertSimplificationSteps (VCFolding ::apply , mixedArithmetic , "2.5 > 2" , "true" );
38+ 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" )));
40+ assertSimplificationSteps (VCFolding ::apply , mixedArithmetic , chain (expect ("2.5 > 2" , "2 + 0.5 > 2" )),
41+ chain (expect ("true" , "2 + 0.5 > 2" )));
4042 }
4143
4244 @ Test
4345 void leavesDivisionAndModuloByZeroUnchanged () {
44- assertSimplificationSteps (VCFolding ::apply , vc ("4 / 0 == 0" ), "4 / 0 == 0" );
45- assertSimplificationSteps (VCFolding ::apply , vc ("4 % 0 == 0" ), "4 % 0 == 0" );
46+ assertSimplificationSteps (VCFolding ::apply , vc ("4 / 0 == 0" ), chain ( expect ( "4 / 0 == 0" , "4 / 0 == 0" )) );
47+ assertSimplificationSteps (VCFolding ::apply , vc ("4 % 0 == 0" ), chain ( expect ( "4 % 0 == 0" , "4 % 0 == 0" )) );
4648 }
4749
4850 @ Test
4951 void leavesRealDivisionAndModuloByZeroUnchanged () {
50- assertSimplificationSteps (VCFolding ::apply , vc ("4.0 / 0.0 == 0.0" ), "4.0 / 0.0 == 0.0" );
51- assertSimplificationSteps (VCFolding ::apply , vc ("4.0 % 0.0 == 0.0" ), "4.0 % 0.0 == 0.0" );
52+ assertSimplificationSteps (VCFolding ::apply , vc ("4.0 / 0.0 == 0.0" ),
53+ chain (expect ("4.0 / 0.0 == 0.0" , "4.0 / 0.0 == 0.0" )));
54+ assertSimplificationSteps (VCFolding ::apply , vc ("4.0 % 0.0 == 0.0" ),
55+ chain (expect ("4.0 % 0.0 == 0.0" , "4.0 % 0.0 == 0.0" )));
5256 }
5357
5458 @ Test
5559 void foldsBooleanBinaryExpressions () {
56- assertSimplificationSteps (VCFolding ::apply , vc ("true && false" ), "false" );
57- assertSimplificationSteps (VCFolding ::apply , vc ("false --> true" ), "true" );
58- assertSimplificationSteps (VCFolding ::apply , vc ("true != false" ), "true" );
60+ assertSimplificationSteps (VCFolding ::apply , vc ("true && false" ), chain ( expect ( "false" , "true && false" )) );
61+ assertSimplificationSteps (VCFolding ::apply , vc ("false --> true" ), chain ( expect ( "true" , "false --> true" )) );
62+ assertSimplificationSteps (VCFolding ::apply , vc ("true != false" ), chain ( expect ( "true" , "true != false" )) );
5963 }
6064
6165 @ Test
6266 void foldsBooleanSubexpressionsInsideLargerExpression () {
63- assertSimplificationSteps (VCFolding ::apply , vc ("true && false || ok" ), "false || ok" );
67+ assertSimplificationSteps (VCFolding ::apply , vc ("true && false || ok" ),
68+ chain (expect ("false || ok" , "true && false || ok" )));
6469 }
6570
6671 @ Test
6772 void foldsNestedConstantsInsideLargerExpression () {
68- assertSimplificationSteps (VCFolding ::apply , vc ("x > 1 + 2" ), "x > 3" );
69- assertSimplificationSteps (VCFolding ::apply , vc ("x + 1 + 2 > 4" ), "x + 3 > 4" );
73+ assertSimplificationSteps (VCFolding ::apply , vc ("x > 1 + 2" ), chain ( expect ( "x > 3" , "x > 1 + 2" )) );
74+ assertSimplificationSteps (VCFolding ::apply , vc ("x + 1 + 2 > 4" ), chain ( expect ( "x + 3 > 4" , "x + 1 + 2 > 4" )) );
7075 }
7176
7277 @ Test
7378 void foldsPartialComparisonsWithoutDroppingSymbolicTerms () {
74- assertSimplificationSteps (VCFolding ::apply , vc ("1 + 2 < x + 4" ), "3 < x + 4" );
79+ assertSimplificationSteps (VCFolding ::apply , vc ("1 + 2 < x + 4" ), chain ( expect ( "3 < x + 4" , "1 + 2 < x + 4" )) );
7580 }
7681
7782 @ Test
7883 void foldsUnaryExpressions () {
79- assertSimplificationSteps (VCFolding ::apply , vc ("!true" ), "false" );
84+ assertSimplificationSteps (VCFolding ::apply , vc ("!true" ), chain ( expect ( "false" , "!true" )) );
8085 VCImplication implication = vc ("-3 < 0" );
8186
82- assertSimplificationSteps (VCFolding ::apply , implication , "-3 < 0" , "true" );
87+ assertSimplificationSteps (VCFolding ::apply , implication , chain (expect ("-3 < 0" , "-3 < 0" )),
88+ chain (expect ("true" , "-3 < 0" )));
8389 }
8490
8591 @ Test
8692 void foldsIteExpressions () {
87- assertSimplificationSteps (VCFolding ::apply , vc ("true ? a : b" ), "a" );
88- assertSimplificationSteps (VCFolding ::apply , vc ("false ? a : b" ), "b" );
89- assertSimplificationSteps (VCFolding ::apply , vc ("cond ? b : b" ), "b" );
93+ assertSimplificationSteps (VCFolding ::apply , vc ("true ? a : b" ), chain ( expect ( "a" , "true ? a : b" )) );
94+ assertSimplificationSteps (VCFolding ::apply , vc ("false ? a : b" ), chain ( expect ( "b" , "false ? a : b" )) );
95+ assertSimplificationSteps (VCFolding ::apply , vc ("cond ? b : b" ), chain ( expect ( "b" , "cond ? b : b" )) );
9096 }
9197
9298 @ Test
9399 void foldsIteBranchesBeforeComparingThem () {
94100 VCImplication implication = vc ("cond ? 1 + 2 : 3" );
95101
96- assertSimplificationSteps (VCFolding ::apply , implication , "cond ? 3 : 3" , "3" );
102+ assertSimplificationSteps (VCFolding ::apply , implication , chain (expect ("cond ? 3 : 3" , "cond ? 1 + 2 : 3" )),
103+ chain (expect ("3" , "cond ? 1 + 2 : 3" )));
97104 }
98105
99106 @ Test
100107 void foldsAdjacentIntegerConstants () {
101- assertSimplificationSteps (VCFolding ::apply , vc ("x + 1 - 2" ), "x - 1" );
102- assertSimplificationSteps (VCFolding ::apply , vc ("x - 1 + 2" ), "x + 1" );
103- assertSimplificationSteps (VCFolding ::apply , vc ("x + 1 + 2" ), "x + 3" );
104- assertSimplificationSteps (VCFolding ::apply , vc ("x + 1 - 1" ), "x" );
108+ assertSimplificationSteps (VCFolding ::apply , vc ("x + 1 - 2" ), chain ( expect ( "x - 1" , "x + 1 - 2" )) );
109+ assertSimplificationSteps (VCFolding ::apply , vc ("x - 1 + 2" ), chain ( expect ( "x + 1" , "x - 1 + 2" )) );
110+ assertSimplificationSteps (VCFolding ::apply , vc ("x + 1 + 2" ), chain ( expect ( "x + 3" , "x + 1 + 2" )) );
111+ assertSimplificationSteps (VCFolding ::apply , vc ("x + 1 - 1" ), chain ( expect ( "x" , "x + 1 - 1" )) );
105112 }
106113
107114 @ Test
108115 void foldsEnumEqualityAndInequality () {
109- assertSimplificationSteps (VCFolding ::apply , vc ("Mode.Photo == Mode.Photo" ), "true" );
110- assertSimplificationSteps (VCFolding ::apply , vc ("Mode.Photo != Mode.Video" ), "true" );
116+ assertSimplificationSteps (VCFolding ::apply , vc ("Mode.Photo == Mode.Photo" ),
117+ chain (expect ("true" , "Mode.Photo == Mode.Photo" )));
118+ assertSimplificationSteps (VCFolding ::apply , vc ("Mode.Photo != Mode.Video" ),
119+ chain (expect ("true" , "Mode.Photo != Mode.Video" )));
111120 }
112121
113122 @ Test
@@ -117,7 +126,8 @@ void foldsResolvedEnumLiterals() {
117126 VCImplication implication = new VCImplication (
118127 new Predicate (new BinaryExpression (limit , "==" , new LiteralInt (3 ))));
119128
120- assertSimplificationSteps (VCFolding ::apply , implication , "3 == 3" , "true" );
129+ assertSimplificationSteps (VCFolding ::apply , implication , chain (expect ("3 == 3" , "Config.LIMIT == 3" )),
130+ chain (expect ("true" , "Config.LIMIT == 3" )));
121131 }
122132
123133 @ Test
@@ -128,20 +138,23 @@ void foldsResolvedEnumLiteralsInsideLargerExpression() {
128138 VCImplication implication = new VCImplication (
129139 new Predicate (new BinaryExpression (arithmetic , "==" , new LiteralInt (5 ))));
130140
131- assertSimplificationSteps (VCFolding ::apply , implication , "3 + 2 == 5" , "5 == 5" , "true" );
141+ 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" )));
132143 }
133144
134145 @ Test
135146 void preservesOriginFromExistingSimplifiedImplication () {
136147 VCImplication substituted = VCSubstitution .apply (vc ("∀x:int. x == 1" , "x + 1 + 2 > 0" ));
137148
138- assertSimplificationSteps (VCFolding ::apply , substituted , "2 + 2 > 0" , "4 > 0" , "true" );
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" )));
139151 }
140152
141153 @ Test
142154 void recordsOriginWhenOnlyGroupIsUnwrapped () {
143155 VCImplication implication = vc ("(x > 0)" );
144- VCImplication result = assertSimplificationSteps (VCFolding ::apply , implication , "x > 0" );
156+ VCImplication result = assertSimplificationSteps (VCFolding ::apply , implication ,
157+ chain (expect ("x > 0" , "x > 0" )));
145158
146159 SimplifiedVCImplication simplified = assertInstanceOf (SimplifiedVCImplication .class , result );
147160 assertEquals ("x > 0" , simplified .getRefinement ().toString ());
@@ -152,12 +165,14 @@ void recordsOriginWhenOnlyGroupIsUnwrapped() {
152165 void recordsOriginWhenFoldingLaterImplication () {
153166 VCImplication implication = vc ("x > 0" , "1 + 2 > 0" );
154167
155- VCImplication result = assertSimplificationSteps (VCFolding ::apply , implication , "x > 0 -> 3 > 0" );
168+ VCImplication result = assertSimplificationSteps (VCFolding ::apply , implication ,
169+ chain (expect ("x > 0" , "x > 0" ), expect ("3 > 0" , "1 + 2 > 0" )));
156170
157171 SimplifiedVCImplication simplifiedNext = assertInstanceOf (SimplifiedVCImplication .class , result .getNext ());
158172 assertEquals ("1 + 2 > 0" , simplifiedNext .getOrigin ().getRefinement ().toString ());
159173
160- result = assertSimplificationSteps (VCFolding ::apply , result , "x > 0 -> true" );
174+ result = assertSimplificationSteps (VCFolding ::apply , result ,
175+ chain (expect ("x > 0" , "x > 0" ), expect ("true" , "1 + 2 > 0" )));
161176
162177 simplifiedNext = assertInstanceOf (SimplifiedVCImplication .class , result .getNext ());
163178 assertEquals ("1 + 2 > 0" , simplifiedNext .getOrigin ().getRefinement ().toString ());
0 commit comments