def test_Cloned_Env_has_same_values(): parent = Env() parent.set("p", 10) child = parent.make_child() child.set("c", 8) new_child = child.clone() assert child.get("c") == 8 assert child.get("p") == 10
def make_graft_env() -> Env: """Create an environment with all the default Graft values""" ret = Env() add_cell_symbols(ret) _add_graft_symbols(ret) return ret
def test_Cloned_env_and_parents_are_independent(): parent = Env() parent.set("p", 10) child = parent.make_child() child.set("c", 8) new_child = child.clone() # Change the old things parent.set("p", 1010) child.set("c", 1008) assert child.get("p") == 1010 assert child.get("c") == 1008 # New child did not pick up changed values assert new_child.get("p") == 10 assert new_child.get("c") == 8 # Change new child and its parent new_child.set("c", 0) new_child.parent().set("p", 1) assert new_child.get("p") == 1 assert new_child.get("c") == 0 # Old stuff was unaffected assert child.get("p") == 1010 assert child.get("c") == 1008
def test_Values_from_parent_are_found_via_get(): world = Env() world.set("w", 2) town = world.make_child() town.set("t", 3) house = town.make_child() house.set("h", 4) assert house.get("h") == 4 assert house.get("t") == 3 assert house.get("w") == 2 assert not town.contains("h") assert not world.contains("t")
def _add_graft_symbols(env: Env): env.set("f", NumberValue(0)) # Fork ID env.set("x", NumberValue(0.0)) # x coord env.set("y", NumberValue(0.0)) # y coord env.set("d", NumberValue(0.0)) # direction in degrees env.set("s", NumberValue(10.0)) # step size env.set("r", NumberValue(0.0)) # red 0-100 (and 0 to -100) env.set("g", NumberValue(0.0)) # green 0-100 (and 0 to -100) env.set("b", NumberValue(0.0)) # blue 0-100 (and 0 to -100) env.set("a", NumberValue(100.0)) # alpha 0-100 (and 0 to -100) env.set("z", NumberValue(5.0)) # brush size env.set("D", NativeFunctionValue(functions.dot)) env.set("F", NativeFunctionValue(functions.fork)) env.set("J", NativeFunctionValue(functions.jump)) env.set("L", NativeFunctionValue(functions.line_to)) env.set("R", NativeFunctionValue(functions.random)) env.set("S", NativeFunctionValue(functions.step))
def add_cell_symbols(env: Env): env.set("endofloop", EndOfLoopValue) env.set("Add", NativeFunctionValue(cellfunctions.add)) env.set("Get", NativeFunctionValue(cellfunctions.get)) env.set("For", NativeFunctionValue(cellfunctions.for_)) env.set("If", NativeFunctionValue(cellfunctions.if_)) env.set("Len", NativeFunctionValue(cellfunctions.len_)) env.set("T", NativeFunctionValue(cellfunctions.times)) env.set("Sin", wrap_math_radinp(math.sin)) env.set("Cos", wrap_math_radinp(math.cos)) env.set("Tan", wrap_math_radinp(math.tan)) env.set("ASin", wrap_math_radout(math.asin)) env.set("ACos", wrap_math_radout(math.acos)) env.set("ATan", wrap_math_radout(math.atan)) env.set("ATan2", wrap_math2_radout(math.atan2)) env.set("Sqrt", wrap_math(math.sqrt)) env.set("Pow", wrap_math2(math.pow)) env.set("Hypot", wrap_math2(math.hypot)) exec_cell(cellstdlib.cellstdlib, env)
def make_env(): ret = ProgramEnv(Env(), None, None, eval_cell) make_graft_env.add_cell_symbols(ret) return ret
def test_Getting_a_name_after_setting_returns_its_value(): env = Env() env.set("mythree", 3) assert env.get("mythree") == 3
def test_After_setting_a_name_Env_contains_it(): env = Env() env.set("myname", "foo") assert env.contains("myname") assert not env.contains("othername")
def test_Empty_Env_does_not_contain_names(): env = Env() assert not env.contains("x")