use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class MathAbsFunctionUnitTest method testCall.
@Test
public void testCall() {
Env env = TestUtils.getTestEnv();
assertEquals(3, this.function.call(env, AviatorNumber.valueOf(-3)).getValue(null));
assertEquals(3.9, this.function.call(env, AviatorNumber.valueOf(-3.9)).getValue(null));
assertEquals(400, this.function.call(env, AviatorNumber.valueOf(400)).getValue(null));
assertEquals(new BigInteger("300000000000000000000000000000000"), this.function.call(env, AviatorNumber.valueOf(new BigInteger("-300000000000000000000000000000000"))).getValue(null));
assertEquals(new BigDecimal("300000000000000000000000000000000"), this.function.call(env, AviatorNumber.valueOf(new BigDecimal("-300000000000000000000000000000000.0000002223333"))).getValue(null));
assertEquals(400, this.function.call(env, AviatorNumber.valueOf(400)).getValue(null));
env.put("a", 300);
env.put("b", -3.14);
env.put("c", new BigInteger("-300000000000000000000000000000000"));
env.put("d", new BigDecimal("-300000000000000000000000000000000.0000002223333"));
assertEquals(300, this.function.call(env, new AviatorJavaType("a")).getValue(null));
assertEquals(3.14, this.function.call(env, new AviatorJavaType("b")).getValue(null));
assertEquals(new BigInteger("300000000000000000000000000000000"), this.function.call(env, new AviatorJavaType("c")).getValue(null));
assertEquals(new BigDecimal("300000000000000000000000000000000"), this.function.call(env, new AviatorJavaType("d")).getValue(null));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class SeqReduceFunctionUnitTest method testReduce_Collection.
@Test
public void testReduce_Collection() {
LinkedHashSet<Integer> a = new LinkedHashSet<Integer>();
for (int i = 0; i < 10; i++) {
a.add(i);
}
SeqReduceFunction fun = new SeqReduceFunction();
AviatorObject result = fun.call(this.env, AviatorRuntimeJavaType.valueOf(a), new AviatorJavaType("+"), AviatorRuntimeJavaType.valueOf(0));
assertNotNull(result);
assertEquals(45, result.getValue(null));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class SeqReduceFunctionUnitTest method testReduce_Map.
@Test
public void testReduce_Map() {
Integer[] a = new Integer[10];
for (int i = 0; i < a.length; i++) {
a[i] = i;
}
SeqReduceFunction fun = new SeqReduceFunction();
AviatorObject result = fun.call(this.env, AviatorRuntimeJavaType.valueOf(a), new AviatorJavaType("+"), AviatorRuntimeJavaType.valueOf(0));
assertNotNull(result);
assertEquals(45, result.getValue(null));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project graphql-calculator by graphql-calculator.
the class ListContain method call.
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject listName, AviatorObject fieldName) {
String fieldNameValue = ((AviatorJavaType) fieldName).getName();
String listNameValue = ((AviatorJavaType) listName).getName();
if (!env.containsKey(listNameValue) || !env.containsKey(fieldNameValue)) {
return AviatorBoolean.FALSE;
}
Collection collection = (Collection) env.get(listNameValue);
return AviatorBoolean.valueOf(collection.contains(env.get(fieldNameValue)));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class IsAFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
Object obj = arg1.getValue(env);
if (obj == null) {
return AviatorBoolean.FALSE;
}
if (arg2.getAviatorType() != AviatorType.JavaType) {
throw new IllegalArgumentException("Invalid class type: " + arg2.desc(env));
}
try {
Class<?> clazz = null;
final String name = ((AviatorJavaType) arg2).getName();
if (TypeUtils.PRIMITIVE_TYPES.containsKey(name)) {
clazz = TypeUtils.PRIMITIVE_TYPES.get(name);
} else {
clazz = ((Env) env).resolveClassSymbol(name, false);
}
return AviatorBoolean.valueOf(clazz.isInstance(obj));
} catch (ClassNotFoundException e) {
throw Reflector.sneakyThrow(e);
}
}
Aggregations