File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
liquidjava-verifier/src/test/java/liquidjava/ast/opt Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 11import static org .junit .Assert .assertEquals ;
2+ import static org .junit .Assert .assertNotNull ;
23
34import org .junit .Test ;
45
56import liquidjava .rj_language .ast .BinaryExpression ;
67import liquidjava .rj_language .ast .LiteralInt ;
78import liquidjava .rj_language .opt .ConstantFolding ;
89import liquidjava .rj_language .opt .derivation_node .ValDerivationNode ;
10+ import liquidjava .rj_language .ast .Var ;
911
1012public class TestOptimizationInt {
1113 @ Test
@@ -15,4 +17,20 @@ public void testIntegerAddFold() {
1517 ValDerivationNode r = ConstantFolding .fold (new ValDerivationNode (b , null ));
1618 assertEquals (new LiteralInt (5 ), r .getValue ());
1719 }
20+
21+ @ Test
22+ public void testNoFoldWhenNonLiteral () {
23+ BinaryExpression b = new BinaryExpression (new LiteralInt (1 ), "+" , new Var ("x" ));
24+ ValDerivationNode r = ConstantFolding .fold (new ValDerivationNode (b , null ));
25+ assertNotNull (r );
26+ }
27+
28+ @ Test
29+ public void testIntegerSubFold () {
30+ BinaryExpression b = new BinaryExpression (new LiteralInt (5 ), "-" , new LiteralInt (2 ));
31+ ValDerivationNode r = ConstantFolding .fold (new ValDerivationNode (b , null ));
32+ assertEquals (new LiteralInt (3 ), r .getValue ());
33+ }
34+
35+
1836}
You can’t perform that action at this time.
0 commit comments