Search in sources :

Example 41 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class TestCompiledExpression method testStringComparison.

@Test
public void testStringComparison() {
    Operand result;
    result = Expression.evaluate(" '010' < '020' ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" '010' < '010' ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" '010' <= '020' ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" '010' <= '010' ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" '010' > '020' ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" '010' > '010' ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" '010' >= '020' ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" '010' >= '010' ", null, null, null);
    Assert.assertTrue((boolean) result.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) Test(org.junit.Test)

Example 42 with Operand

use of com.dexels.navajo.document.Operand 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 43 with Operand

use of com.dexels.navajo.document.Operand 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)

Example 44 with Operand

use of com.dexels.navajo.document.Operand 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 45 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class TestCompiledPercentageExpression method testSubtractWithPercentage.

@Test
public void testSubtractWithPercentage() {
    Operand result;
    result = Expression.evaluate("ToPercentage(15) - ToPercentage(10)", null, null, null);
    Assert.assertEquals(new Percentage(5), result.value);
    result = Expression.evaluate("15 - ToPercentage(10)", null, null, null);
    Assert.assertEquals(new Percentage(5), result.value);
    result = Expression.evaluate("ToPercentage(15) - 10", null, null, null);
    Assert.assertEquals(new Percentage(5), result.value);
    result = Expression.evaluate("ToLong(15) - ToPercentage(10)", null, null, null);
    Assert.assertEquals(new Percentage(5), result.value);
    result = Expression.evaluate("ToPercentage(15) - ToLong(10)", null, null, null);
    Assert.assertEquals(new Percentage(5), result.value);
    result = Expression.evaluate("15.0 - ToPercentage(10)", null, null, null);
    Assert.assertEquals(new Percentage(5), result.value);
    result = Expression.evaluate("ToPercentage(15) - 10.0", null, null, null);
    Assert.assertEquals(new Percentage(5), result.value);
}
Also used : Percentage(com.dexels.navajo.document.types.Percentage) Operand(com.dexels.navajo.document.Operand) Test(org.junit.Test)

Aggregations

Operand (com.dexels.navajo.document.Operand)95 Test (org.junit.Test)57 Message (com.dexels.navajo.document.Message)22 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)20 Navajo (com.dexels.navajo.document.Navajo)20 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)14 ArrayList (java.util.ArrayList)12 Selection (com.dexels.navajo.document.Selection)11 Property (com.dexels.navajo.document.Property)10 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)10 Access (com.dexels.navajo.script.api.Access)10 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)10 NavajoException (com.dexels.navajo.document.NavajoException)9 TipiLink (com.dexels.navajo.expression.api.TipiLink)9 Optional (java.util.Optional)9 FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)8 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)6 SystemException (com.dexels.navajo.script.api.SystemException)6 List (java.util.List)6