use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class PrintFunctionUnitTest method testCall_WithTwoArgument.
@Test
public void testCall_WithTwoArgument() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Map<String, Object> env = new HashMap<String, Object>();
env.put("out", out);
this.fun.call(env, new AviatorJavaType("out"), new AviatorString("hello"));
out.flush();
out.close();
byte[] data = out.toByteArray();
assertEquals("hello", new String(data));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class SeqFilterFunctionUnitTest method testFilter_map.
@Test
public void testFilter_map() {
Map<Integer, String> data = new HashMap<>();
for (int i = 0; i < 5; i++) {
data.put(i, "a" + i);
}
Map<String, Object> env = new HashMap<>();
SeqPredicateFunction predicate = new SeqPredicateFunction("eq_temp_1", OperatorType.EQ, new AviatorString("a1"), new AviatorString("value"));
env.putAll(AviatorEvaluator.FUNC_MAP);
env.put("eq_temp_1", predicate);
SeqFilterFunction fun = new SeqFilterFunction();
AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf(data), new AviatorJavaType("eq_temp_1"));
Map map = ((Map) result.getValue(null));
assertEquals(1, map.size());
for (Object value : map.values()) {
assertEquals("a1", value.toString());
}
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class SeqReduceFunctionUnitTest method testReduce_String.
@Test
public void testReduce_String() {
SeqReduceFunction fun = new SeqReduceFunction();
AviatorObject result = fun.call(AviatorEvaluator.FUNC_MAP, AviatorRuntimeJavaType.valueOf("hello"), new AviatorJavaType("+"), AviatorRuntimeJavaType.valueOf(0));
assertEquals("0hello", result.getValue(null));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class MathLog10FunctionUnitTest method testCall.
@Test
public void testCall() {
assertEquals(2.0, this.function.call(null, AviatorNumber.valueOf(100)).getValue(null));
assertEquals(3.0, this.function.call(null, AviatorNumber.valueOf(1000)).getValue(null));
assertEquals(2.60, 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(4.0, this.function.call(env, new AviatorJavaType("a")).getValue(null));
assertEquals(0.9542, this.function.call(env, new AviatorJavaType("b")).getValue(null));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class MathPowFunctionUnitTest method testCall.
@Test
public void testCall() {
assertEquals(Math.pow(3, 2), this.function.call(null, AviatorNumber.valueOf(3), AviatorNumber.valueOf(2)).getValue(null));
assertEquals(Math.pow(10.9, 4.0), this.function.call(null, AviatorNumber.valueOf(10.9), AviatorNumber.valueOf(4.0)).getValue(null));
assertEquals(Math.pow(20, -3), this.function.call(null, AviatorNumber.valueOf(20), AviatorNumber.valueOf(-3)).getValue(null));
assertEquals(new BigInteger("1000000000000000000000000000000000000").pow(3), this.function.call(null, AviatorNumber.valueOf(new BigInteger("1000000000000000000000000000000000000")), AviatorNumber.valueOf(3)).getValue(null));
assertEquals(new BigDecimal("1000000000000000000000000000000000000.000022222").pow(3, RuntimeUtils.getMathContext(null)), this.function.call(null, AviatorNumber.valueOf(new BigDecimal("1000000000000000000000000000000000000.000022222")), AviatorNumber.valueOf(3)).getValue(null));
Map<String, Object> env = new HashMap<String, Object>();
env.put("a", 3.0);
env.put("b", 9.0);
assertEquals(Math.pow(3.0, 9.0), this.function.call(env, new AviatorJavaType("a"), new AviatorJavaType("b")).getValue(null));
assertEquals(Math.pow(9.0, 4), this.function.call(env, new AviatorJavaType("b"), AviatorNumber.valueOf(4)).getValue(null));
assertEquals(Math.pow(-2.3, 3.0), this.function.call(env, AviatorNumber.valueOf(-2.3), new AviatorJavaType("a")).getValue(null));
}
Aggregations