use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class TestCompiledExpression method testFunctionCallWithNamedParams.
@Test
public void testFunctionCallWithNamedParams() throws ParseException {
FunctionInterface testFunction = new AddTestFunction();
FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "blib", "bleb", "blab");
FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("addtest", fd);
String expression = "addtest(aap='blub',3+5,4)";
StringReader sr = new StringReader(expression);
CompiledParser cp = new CompiledParser(sr);
cp.Expression();
SimpleNode atn = (SimpleNode) cp.getJJTree().rootNode();
List<String> problems = new ArrayList<>();
ContextExpression ne = atn.interpretToLambda(problems, expression, fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
Operand result = ne.apply();
Assert.assertEquals("monkey", result.value);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class TestCompiledMoneyExpression method testSubtractWithMoney.
@Test
public void testSubtractWithMoney() {
Operand result;
result = Expression.evaluate("ToMoney(15) - ToMoney(10)", null, null, null);
Assert.assertEquals(new Money(5), result.value);
result = Expression.evaluate("15 - ToMoney(10)", null, null, null);
Assert.assertEquals(new Money(5), result.value);
result = Expression.evaluate("ToMoney(15) - 10", null, null, null);
Assert.assertEquals(new Money(5), result.value);
result = Expression.evaluate("ToLong(15) - ToMoney(10)", null, null, null);
Assert.assertEquals(new Money(5), result.value);
result = Expression.evaluate("ToMoney(15) - ToLong(10)", null, null, null);
Assert.assertEquals(new Money(5), result.value);
result = Expression.evaluate("15.0 - ToMoney(10)", null, null, null);
Assert.assertEquals(new Money(5), result.value);
result = Expression.evaluate("ToMoney(15) - 10.0", null, null, null);
Assert.assertEquals(new Money(5), result.value);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class TestCompiledStringExpression method testAddIntegerAndString.
@Test
public void testAddIntegerAndString() {
Operand result = Expression.evaluate("15 + 'bla'", null, null, null);
assertEquals("15bla", result.value);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class TestCompiledLongExpression method testMultiplyWithLongs.
@Test
public void testMultiplyWithLongs() {
FunctionInterface helperFunction = new GiveLongTestFunction();
FunctionDefinition fd = new FunctionDefinition(helperFunction.getClass().getName(), "description", "input", "result");
FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
Operand result;
result = Expression.evaluate("ToLong(3) * ToLong(1)", null, null, null);
Assert.assertEquals(3L, (long) result.value);
result = Expression.evaluate("3 * ToLong(1)", null, null, null);
Assert.assertEquals(3L, (long) result.value);
result = Expression.evaluate("ToLong(3) * 1", null, null, null);
Assert.assertEquals(3L, (long) result.value);
result = Expression.evaluate("3.0 * ToLong(1)", null, null, null);
Assert.assertEquals(3L, (double) result.value, 0.000001);
result = Expression.evaluate("ToLong(3) * 1.0", null, null, null);
Assert.assertEquals(3L, (double) result.value, 0.000001);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class TestCompiledPercentageExpression method testAddWithPercentage.
@Test
public void testAddWithPercentage() {
Operand result;
result = Expression.evaluate("ToPercentage(15) + ToPercentage(10)", null, null, null);
Assert.assertEquals(new Percentage(25), result.value);
result = Expression.evaluate("15 + ToPercentage(10)", null, null, null);
Assert.assertEquals(new Percentage(25), result.value);
result = Expression.evaluate("ToPercentage(15) + 10", null, null, null);
Assert.assertEquals(new Percentage(25), result.value);
result = Expression.evaluate("ToLong(15) + ToPercentage(10)", null, null, null);
Assert.assertEquals(new Percentage(25), result.value);
result = Expression.evaluate("ToPercentage(15) + ToLong(10)", null, null, null);
Assert.assertEquals(new Percentage(25), result.value);
result = Expression.evaluate("15.0 + ToPercentage(10)", null, null, null);
Assert.assertEquals(new Percentage(25), result.value);
result = Expression.evaluate("ToPercentage(15) + 10.0", null, null, null);
Assert.assertEquals(new Percentage(25), result.value);
}
Aggregations