Search in sources :

Example 31 with AviatorJavaType

use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.

the class SeqMapFunctionUnitTest method testMap_String.

@Test
public void testMap_String() {
    Env env = TestUtils.getTestEnv();
    SeqMapFunction fun = new SeqMapFunction();
    AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf("hello"), new AviatorJavaType("string.length"));
    List list = (List) result.getValue(null);
    assertEquals(5, list.size());
    for (Object val : list) {
        assertEquals(val, 1);
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) List(java.util.List) LinkedList(java.util.LinkedList) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Env(com.googlecode.aviator.utils.Env) Test(org.junit.Test)

Example 32 with AviatorJavaType

use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.

the class MathLogFunctionUnitTest method testCall.

@Test
public void testCall() {
    Env env = TestUtils.getTestEnv();
    assertEquals(2.197, this.function.call(env, AviatorNumber.valueOf(9)).getValue(null));
    assertEquals(4.394, this.function.call(env, AviatorNumber.valueOf(81)).getValue(null));
    assertEquals(5.991, this.function.call(env, AviatorNumber.valueOf(400)).getValue(null));
    assertEquals(new BigDecimal("5.991464547107981986870447152285084"), this.function.call(env, AviatorNumber.valueOf(new BigInteger("400"))).getValue(null));
    assertEquals(new BigDecimal("6.907755268982137002053974030719759"), this.function.call(env, AviatorNumber.valueOf(new BigDecimal("999.99999"))).getValue(null));
    env.put("a", 400);
    env.put("b", 9.0);
    assertEquals(5.991, this.function.call(env, new AviatorJavaType("a")).getValue(null));
    assertEquals(2.197, this.function.call(env, new AviatorJavaType("b")).getValue(null));
}
Also used : AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) BigInteger(java.math.BigInteger) Env(com.googlecode.aviator.utils.Env) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 33 with AviatorJavaType

use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.

the class MathSinFunctionUnitTest method testCall.

@Test
public void testCall() {
    assertEquals(Math.sin(30), this.function.call(null, AviatorNumber.valueOf(30)).getValue(null));
    assertEquals(Math.sin(1020.999), this.function.call(null, AviatorNumber.valueOf(1020.999)).getValue(null));
    assertEquals(Math.sin(400), this.function.call(null, AviatorNumber.valueOf(400)).getValue(null));
    Map<String, Object> env = new HashMap<String, Object>();
    env.put("a", 10000);
    env.put("b", 9.0);
    assertEquals(Math.sin(10000), this.function.call(env, new AviatorJavaType("a")).getValue(null));
    assertEquals(Math.sin(9.0), this.function.call(env, new AviatorJavaType("b")).getValue(null));
}
Also used : HashMap(java.util.HashMap) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) Test(org.junit.Test)

Example 34 with AviatorJavaType

use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.

the class MathTanFunctionUnitTest method testCall.

@Test
public void testCall() {
    assertEquals(Math.tan(30), this.function.call(null, AviatorNumber.valueOf(30)).getValue(null));
    assertEquals(Math.tan(1020.999), this.function.call(null, AviatorNumber.valueOf(1020.999)).getValue(null));
    assertEquals(Math.tan(400), this.function.call(null, AviatorNumber.valueOf(400)).getValue(null));
    Map<String, Object> env = new HashMap<String, Object>();
    env.put("a", 10000);
    env.put("b", 9.0);
    assertEquals(Math.tan(10000), this.function.call(env, new AviatorJavaType("a")).getValue(null));
    assertEquals(Math.tan(9.0), this.function.call(env, new AviatorJavaType("b")).getValue(null));
}
Also used : HashMap(java.util.HashMap) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) Test(org.junit.Test)

Example 35 with AviatorJavaType

use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.

the class SeqReduceFunctionUnitTest method testReduce_NullArray.

@Test(expected = ExpressionRuntimeException.class)
public void testReduce_NullArray() {
    Integer[] a = new Integer[10];
    for (int i = 0; i < a.length; i++) {
        if (i % 2 == 0) {
            a[i] = i;
        }
    }
    SeqReduceFunction fun = new SeqReduceFunction();
    AviatorObject result = fun.call(this.env, AviatorRuntimeJavaType.valueOf(a), new AviatorJavaType("+"), AviatorRuntimeJavaType.valueOf(0));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) Test(org.junit.Test)

Aggregations

AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)45 Test (org.junit.Test)29 AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)25 HashMap (java.util.HashMap)16 AviatorString (com.googlecode.aviator.runtime.type.AviatorString)11 AviatorFunction (com.googlecode.aviator.runtime.type.AviatorFunction)10 Env (com.googlecode.aviator.utils.Env)10 FunctionNotFoundException (com.googlecode.aviator.exception.FunctionNotFoundException)6 LinkedList (java.util.LinkedList)4 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)3 FunctionParam (com.googlecode.aviator.runtime.FunctionParam)2 BinaryFunction (com.googlecode.aviator.runtime.function.system.BinaryFunction)2 Collector (com.googlecode.aviator.runtime.type.Collector)2 Sequence (com.googlecode.aviator.runtime.type.Sequence)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 AviatorEvaluatorInstance (com.googlecode.aviator.AviatorEvaluatorInstance)1 CodeGenerator (com.googlecode.aviator.code.CodeGenerator)1