Added while loops to the expression parser.

Also added a test case.
Iterations are currently limited to 256 maximum.
This commit is contained in:
TomyLobo
2011-11-22 06:07:22 +01:00
parent aa43975e34
commit f217be0bdf
5 changed files with 96 additions and 4 deletions

View File

@ -84,7 +84,12 @@ public class ExpressionTest {
final Expression expression2 = Expression.compile("if (0) if (1) x=5; y=4;", "x", "y");
expression2.evaluate(1, 2);
assertEquals(4, expression2.getVariable("y").getValue(), 0);
}
@Test
public void testWhile() throws ExpressionException {
assertEquals(5, simpleEval("c=5; a=0; while (c > 0) { ++a; --c; } a"), 0);
assertEquals(5, simpleEval("c=5; a=0; do { ++a; --c; } while (c > 0) a"), 0);
}
private double simpleEval(String expression) throws ExpressionException {