Search in sources :

Example 1 with Statement

use of org.eclipse.xtext.example.arithmetics.arithmetics.Statement in project xtext-eclipse by eclipse.

the class CalculatorTest method check.

protected void check(final double expected, final String expression) throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("module test ");
    _builder.append(expression);
    final org.eclipse.xtext.example.arithmetics.arithmetics.Module module = this.parseHelper.parse(_builder);
    BigDecimal result = this.calculator.evaluate(IterableExtensions.<Expression>head(Iterables.<Expression>filter(IterableExtensions.<Statement>head(module.getStatements()).eContents(), Expression.class)));
    Assert.assertEquals(expected, result.doubleValue(), 0.0001);
}
Also used : Expression(org.eclipse.xtext.example.arithmetics.arithmetics.Expression) Statement(org.eclipse.xtext.example.arithmetics.arithmetics.Statement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) BigDecimal(java.math.BigDecimal)

Example 2 with Statement

use of org.eclipse.xtext.example.arithmetics.arithmetics.Statement in project xtext-eclipse by eclipse.

the class CalculatorTest method evaluatesTo.

private void evaluatesTo(CharSequence content, double expected) throws Exception {
    Module module = parseHelper.parse("module test " + content);
    Statement firstStatement = module.getStatements().get(0);
    Iterable<Expression> expressions = Iterables.filter(firstStatement.eContents(), Expression.class);
    Expression expression = Iterables.getFirst(expressions, null);
    BigDecimal result = calculator.evaluate(expression);
    Assert.assertEquals(expected, result.doubleValue(), 0.0001);
}
Also used : Expression(org.eclipse.xtext.example.arithmetics.arithmetics.Expression) Statement(org.eclipse.xtext.example.arithmetics.arithmetics.Statement) Module(org.eclipse.xtext.example.arithmetics.arithmetics.Module) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)2 Expression (org.eclipse.xtext.example.arithmetics.arithmetics.Expression)2 Statement (org.eclipse.xtext.example.arithmetics.arithmetics.Statement)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Module (org.eclipse.xtext.example.arithmetics.arithmetics.Module)1