@Test public void shouldAllowTheSettingOfTheEnvironment() { assertThat(Environment.get(), is(nullValue())); assertThat(Environment.is(null), is(true)); assertThat(Environment.is("anything else"), is(false)); Environment.set("test"); assertThat(Environment.get(), is("test")); assertThat(Environment.is("test"), is(true)); assertThat(Environment.is(null), is(false)); assertThat(Environment.is("Test"), is(false)); Environment.set("test2"); assertThat(Environment.get(), is("test2")); assertThat(Environment.is("test2"), is(true)); assertThat(Environment.is("test"), is(false)); }
public VariableInfo getVariable(String id) { VariableInfo vi = null; for (Enumeration<Environment> e = this.elements(); e.hasMoreElements(); ) { Environment env = e.nextElement(); vi = env.get(id); if (vi != null) return vi; } return null; }
@Override public Object evaluate(Environment environment) { Environment closure = new Environment(environment); for (int i = 0; i < getNumberOfArguments(); i++) { closure.set(variableNames[i], getArgument(i).evaluate(environment)); } Node functionBody = environment.get(Node.class, functionName); return functionBody.evaluate(closure); }
public Object eval(Environment env) { Object value = env.get(name()); if (value == null) throw new StoneException("undefined name: " + name(), this); else return value; }
/** Evalaution method for id Fact Nodes. Evaluates the id portion. */ public double eval(Environment env) throws EvalException { return env.get(pos, id); }
@Test public final void test() { final Environment<String, String> env = new Environment<String, String>(); env.put("x", "1"); env.put("y", "2"); assertEquals("1", env.get("x")); assertEquals("2", env.get("y")); env.put("x", "3"); assertEquals("3", env.get("x")); assertEquals("2", env.get("y")); env.beginScope(); assertEquals("3", env.get("x")); assertEquals("2", env.get("y")); env.put("x", "4"); assertEquals("4", env.get("x")); assertEquals("2", env.get("y")); env.beginScope(); assertEquals("4", env.get("x")); assertEquals("2", env.get("y")); env.put("y", "5"); env.put("z", "6"); assertEquals("4", env.get("x")); assertEquals("5", env.get("y")); assertEquals("6", env.get("z")); env.endScope(); assertEquals("4", env.get("x")); assertEquals("2", env.get("y")); assertEquals(null, env.get("z")); env.put("y", "7"); assertEquals("4", env.get("x")); assertEquals("7", env.get("y")); env.endScope(); assertEquals("3", env.get("x")); assertEquals("2", env.get("y")); }