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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations