@Test void testUnits() { final var context = new Context(); BundleLoader.loadSingle(context, CompositionBundle.class); context.functions().put("rate", context.functions().get("composition")); Value value; value = eval("rate(30) t = 1 sec", context); assertThat(value.asDouble(), closeTo(30, 0.0001)); value = eval("rate(30) t = 5 sec", context); assertThat(value.asDouble(), closeTo(150, 0.0001)); value = eval("rate(30) t = 0.5 sec", context); assertThat(value.asDouble(), closeTo(15, 0.0001)); value = eval("rate(30) t = 1000 ms", context); assertThat(value.asDouble(), closeTo(30, 0.0001)); value = eval("rate(30) t = 333 ms", context); assertThat(value.asDouble(), closeTo(10, 0.01)); value = eval("rate(25) t = 1 sec", context); assertThat(value.asDouble(), closeTo(25, 0.0001)); value = eval("rate(25) t = 1000 ms", context); assertThat(value.asDouble(), closeTo(25, 0.0001)); }
@Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); }
InterpreterVisitor implements ResultVisitor<Value, Context> { @Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); } }
InterpreterVisitor implements ResultVisitor<Value, Context> { @Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); }  }
InterpreterVisitor implements ResultVisitor<Value, Context> { @Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); }  @Override Value visit(AccessNode node, Context context); @Override Value visit(ArrayNode node, Context context); @Override Value visit(AssignNode node, Context context); @Override Value visit(BlockNode node, Context context); @Override Value visit(FunctionNode node, Context context); @Override Value visit(MapNode node, Context context); @Override Value visit(PropertyNode node, Context context); @Override Value visit(UnaryNode node, Context context); @Override Value visit(UnitNode node, Context context); @Override Value visit(ValueNode node, Context context); @Override Value visit(VariableNode node, Context context); @Override Value get(AccessNode node, Context context); @Override Value set(AccessNode node, Value value, Context context); @Override Value get(VariableNode node, Context context); @Override Value set(VariableNode node, Value value, Context context); }
InterpreterVisitor implements ResultVisitor<Value, Context> { @Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); }  @Override Value visit(AccessNode node, Context context); @Override Value visit(ArrayNode node, Context context); @Override Value visit(AssignNode node, Context context); @Override Value visit(BlockNode node, Context context); @Override Value visit(FunctionNode node, Context context); @Override Value visit(MapNode node, Context context); @Override Value visit(PropertyNode node, Context context); @Override Value visit(UnaryNode node, Context context); @Override Value visit(UnitNode node, Context context); @Override Value visit(ValueNode node, Context context); @Override Value visit(VariableNode node, Context context); @Override Value get(AccessNode node, Context context); @Override Value set(AccessNode node, Value value, Context context); @Override Value get(VariableNode node, Context context); @Override Value set(VariableNode node, Value value, Context context);  }