Search in sources :

Example 11 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class TestMathFunctions method testRoundToWhole.

@Test
public void testRoundToWhole() {
    FunctionInterface round = fff.getInstance(cl, "Round");
    round.reset();
    round.insertFloatOperand(10.5);
    round.insertIntegerOperand(0);
    double actual = (Double) round.evaluateWithTypeChecking();
    assertEquals(11.0, actual, 0.000001);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Test(org.junit.Test)

Example 12 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class TestMathFunctions method testMaxNumberList.

@Test
public void testMaxNumberList() {
    FunctionInterface max = fff.getInstance(cl, "Max");
    max.reset();
    List<Object> numbers = new ArrayList<>();
    numbers.add(Math.PI);
    numbers.add(3);
    numbers.add(5L);
    max.insertListOperand(numbers);
    double actual = (Double) max.evaluateWithTypeChecking();
    assertEquals(5.0, actual, 0.000001);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class TestMathFunctions method testMaxDateList.

@Test
public void testMaxDateList() throws ParseException {
    FunctionInterface max = fff.getInstance(cl, "Max");
    max.reset();
    SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd");
    List<Date> dates = new ArrayList<>();
    dates.add(parser.parse("2017-11-10"));
    dates.add(parser.parse("2015-11-10"));
    dates.add(parser.parse("2019-10-11"));
    max.insertListOperand(dates);
    Date actual = (Date) max.evaluateWithTypeChecking();
    assertEquals(parser.parse("2019-10-11"), actual);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 14 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class StandardFunctionsTest method testGetFileExtension.

@Test
public void testGetFileExtension() {
    FunctionInterface fi = fff.getInstance(cl, "GetFileExtension");
    Navajo doc = createTestNavajo();
    fi.setInMessage(doc);
    fi.reset();
    fi.insertOperand(Operand.NULL);
    Object o = fi.evaluateWithTypeChecking();
    assertNull(o);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Navajo(com.dexels.navajo.document.Navajo) Test(org.junit.Test)

Example 15 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class StandardFunctionsTest method testIsEmpty.

@Test
public void testIsEmpty() {
    FunctionInterface fi = fff.getInstance(cl, "IsEmpty");
    // Empty String.
    fi.reset();
    fi.insertStringOperand("");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.TRUE, o);
    // Non Empty String.
    fi.reset();
    fi.insertStringOperand("aap");
    o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.FALSE, o);
    // Null value.
    fi.reset();
    fi.insertOperand(Operand.NULL);
    o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.TRUE, o);
    // Empty list
    fi.reset();
    fi.insertListOperand(new ArrayList<Object>());
    o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.TRUE, o);
    // Non Empty list.
    fi.reset();
    boolean thing = new ArrayList<String>().add("noot");
    fi.insertBooleanOperand(thing);
    o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.FALSE, o);
    // Empty Binary.
    fi.reset();
    fi.insertBinaryOperand(new Binary());
    o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.TRUE, o);
    // Non Empty Binary.
    fi.reset();
    fi.insertBinaryOperand(new Binary("aap".getBytes()));
    o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.FALSE, o);
    // Non empty Clocktime.
    fi.reset();
    fi.insertClockTimeOperand(new ClockTime(new Date()));
    o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.FALSE, o);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) CapString(com.dexels.navajo.functions.CapString) Binary(com.dexels.navajo.document.types.Binary) ClockTime(com.dexels.navajo.document.types.ClockTime) Date(java.util.Date) Test(org.junit.Test)

Aggregations

FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)161 Test (org.junit.Test)153 Navajo (com.dexels.navajo.document.Navajo)26 FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)20 ArrayList (java.util.ArrayList)16 Date (java.util.Date)16 Operand (com.dexels.navajo.document.Operand)10 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)10 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)7 CapString (com.dexels.navajo.functions.CapString)7 StringReader (java.io.StringReader)5 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)4 AddTestFunction (com.dexels.navajo.expression.compiled.AddTestFunction)4 Binary (com.dexels.navajo.document.types.Binary)3 CheckInteger (com.dexels.navajo.functions.CheckInteger)3 SimpleDateFormat (java.text.SimpleDateFormat)3 List (java.util.List)3 Message (com.dexels.navajo.document.Message)2 Property (com.dexels.navajo.document.Property)2 ClockTime (com.dexels.navajo.document.types.ClockTime)2