Search in sources :

Example 1 with GiveLongTestFunction

use of com.dexels.navajo.expression.compiled.GiveLongTestFunction in project navajo by Dexels.

the class TestCompiledStringExpression method testAddLongAndString.

@Test
public void testAddLongAndString() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    Operand result = Expression.evaluate("ToLong(15) + 'bla'", null, null, null);
    assertEquals("15bla", result.value);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Test(org.junit.Test)

Example 2 with GiveLongTestFunction

use of com.dexels.navajo.expression.compiled.GiveLongTestFunction in project navajo by Dexels.

the class TestCompiledStringExpression method testAddStringAndLong.

@Test
public void testAddStringAndLong() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    Operand result = Expression.evaluate("'bla' + ToLong(10)", null, null, null);
    assertEquals("bla10", result.value);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Test(org.junit.Test)

Example 3 with GiveLongTestFunction

use of com.dexels.navajo.expression.compiled.GiveLongTestFunction in project navajo by Dexels.

the class TestCompiledStringExpression method testSubtractLongAndString.

@Test(expected = TMLExpressionException.class)
public void testSubtractLongAndString() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    Expression.evaluate("ToLong(15) - 'bla'", null, null, null);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Test(org.junit.Test)

Example 4 with GiveLongTestFunction

use of com.dexels.navajo.expression.compiled.GiveLongTestFunction in project navajo by Dexels.

the class TestCompiledLongExpression method testAddWithLongs.

@Test
public void testAddWithLongs() {
    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(1) + ToLong(1)", null, null, null);
    Assert.assertEquals(2L, (long) result.value);
    result = Expression.evaluate("1 + ToLong(1)", null, null, null);
    Assert.assertEquals(2L, (long) result.value);
    result = Expression.evaluate("ToLong(1) + 1", null, null, null);
    Assert.assertEquals(2L, (long) result.value);
    result = Expression.evaluate("1.0 + ToLong(1)", null, null, null);
    Assert.assertEquals(2.0, (double) result.value, 0.000001);
    result = Expression.evaluate("ToLong(1) + 1.0", null, null, null);
    Assert.assertEquals(2.0, (double) result.value, 0.000001);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Test(org.junit.Test)

Example 5 with GiveLongTestFunction

use of com.dexels.navajo.expression.compiled.GiveLongTestFunction in project navajo by Dexels.

the class TestCompiledLongExpression method testDivideWithLongs.

@Test
public void testDivideWithLongs() {
    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(8) / ToLong(2)", null, null, null);
    Assert.assertEquals(4.0, (double) result.value, 0.000001);
    result = Expression.evaluate("8 / ToLong(2)", null, null, null);
    Assert.assertEquals(4.0, (double) result.value, 0.000001);
    result = Expression.evaluate("ToLong(8) / 2", null, null, null);
    Assert.assertEquals(4.0, (double) result.value, 0.000001);
    result = Expression.evaluate("8.0 / ToLong(2)", null, null, null);
    Assert.assertEquals(4.0, (double) result.value, 0.000001);
    result = Expression.evaluate("ToLong(8) / 2.0", null, null, null);
    Assert.assertEquals(4.0, (double) result.value, 0.000001);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Test(org.junit.Test)

Aggregations

FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)10 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)10 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)10 Test (org.junit.Test)8 Operand (com.dexels.navajo.document.Operand)6 Before (org.junit.Before)2 GiveMoneyTestFunction (com.dexels.navajo.expression.compiled.GiveMoneyTestFunction)1 GivePercentageTestFunction (com.dexels.navajo.expression.compiled.GivePercentageTestFunction)1