Search in sources :

Example 16 with AviatorJavaType

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

the class MathRoundFunctionUnitTest method testCall.

@Test
public void testCall() {
    assertEquals(Math.round(30), this.function.call(null, AviatorNumber.valueOf(30)).getValue(null));
    assertEquals(Math.round(1020.999), this.function.call(null, AviatorNumber.valueOf(1020.999)).getValue(null));
    assertEquals(Math.round(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.round(10000), this.function.call(env, new AviatorJavaType("a")).getValue(null));
    assertEquals(Math.round(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 17 with AviatorJavaType

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

the class MathSqrtFunctionUnitTest method testCall.

@Test
public void testCall() {
    assertEquals(3.0, this.function.call(null, AviatorNumber.valueOf(9)).getValue(null));
    assertEquals(9.0, this.function.call(null, AviatorNumber.valueOf(81)).getValue(null));
    assertEquals(20.0, this.function.call(null, AviatorNumber.valueOf(400)).getValue(null));
    Map<String, Object> env = new HashMap<String, Object>();
    env.put("a", 400);
    env.put("b", 9.0);
    assertEquals(20.0, this.function.call(env, new AviatorJavaType("a")).getValue(null));
    assertEquals(3.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 18 with AviatorJavaType

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

the class FunctionUtilsUnitTest method testGetFunction_neg.

@Test
public void testGetFunction_neg() {
    AviatorFunction fun = FunctionUtils.getFunction(new AviatorJavaType("-"), AviatorEvaluator.FUNC_MAP, 1);
    assertNotNull(fun);
    assertTrue(fun instanceof BinaryFunction);
    assertEquals("-neg", fun.getName());
    assertEquals(OperatorType.NEG, ((BinaryFunction) fun).getOpType());
}
Also used : BinaryFunction(com.googlecode.aviator.runtime.function.system.BinaryFunction) AviatorFunction(com.googlecode.aviator.runtime.type.AviatorFunction) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) Test(org.junit.Test)

Example 19 with AviatorJavaType

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

the class FunctionUtilsUnitTest method testGetFunction_sub.

@Test
public void testGetFunction_sub() {
    AviatorFunction fun = FunctionUtils.getFunction(new AviatorJavaType("-"), AviatorEvaluator.FUNC_MAP, 2);
    assertNotNull(fun);
    assertTrue(fun instanceof BinaryFunction);
    assertEquals("-sub", fun.getName());
    assertEquals(OperatorType.SUB, ((BinaryFunction) fun).getOpType());
}
Also used : BinaryFunction(com.googlecode.aviator.runtime.function.system.BinaryFunction) AviatorFunction(com.googlecode.aviator.runtime.type.AviatorFunction) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) Test(org.junit.Test)

Example 20 with AviatorJavaType

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

the class FunctionUtilsUnitTest method testGetFunction_Normal.

@Test
public void testGetFunction_Normal() {
    AviatorFunction fun = FunctionUtils.getFunction(new AviatorJavaType("map"), AviatorEvaluator.FUNC_MAP, 2);
    assertNotNull(fun);
    assertTrue(fun instanceof SeqMapFunction);
}
Also used : AviatorFunction(com.googlecode.aviator.runtime.type.AviatorFunction) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) SeqMapFunction(com.googlecode.aviator.runtime.function.seq.SeqMapFunction) 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