Search in sources :

Example 6 with GiveLongTestFunction

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

the class TestCompiledLongExpression method testSubtractWithLongs.

@Test
public void testSubtractWithLongs() {
    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(2) - ToLong(1)", null, null, null);
    Assert.assertEquals(1L, (long) result.value);
    result = Expression.evaluate("2 - ToLong(1)", null, null, null);
    Assert.assertEquals(1L, (long) result.value);
    result = Expression.evaluate("ToLong(2) - 1", null, null, null);
    Assert.assertEquals(1L, (long) result.value);
    result = Expression.evaluate("2.0 - ToLong(1)", null, null, null);
    Assert.assertEquals(1.0, (double) result.value, 0.000001);
    result = Expression.evaluate("ToLong(2) - 1.0", null, null, null);
    Assert.assertEquals(1.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 7 with GiveLongTestFunction

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

the class TestCompiledPercentageExpression method setup.

@Before
public void setup() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    FunctionInterface givePercentageFunction = new GivePercentageTestFunction();
    fd = new FunctionDefinition(givePercentageFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToPercentage", fd);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) GivePercentageTestFunction(com.dexels.navajo.expression.compiled.GivePercentageTestFunction) Before(org.junit.Before)

Example 8 with GiveLongTestFunction

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

the class TestCompiledMoneyExpression method setup.

@Before
public void setup() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    FunctionInterface giveMoneyFunction = new GiveMoneyTestFunction();
    fd = new FunctionDefinition(giveMoneyFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToMoney", fd);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) GiveMoneyTestFunction(com.dexels.navajo.expression.compiled.GiveMoneyTestFunction) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Before(org.junit.Before)

Example 9 with GiveLongTestFunction

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

the class TestCompiledStringExpression method testSubtractStringAndLong.

@Test(expected = TMLExpressionException.class)
public void testSubtractStringAndLong() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    Expression.evaluate("'bla' - ToLong(10)", 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 10 with GiveLongTestFunction

use of com.dexels.navajo.expression.compiled.GiveLongTestFunction 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);
}
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