示例#1
0
文件: test_env.py 项目: yazici/graft
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
示例#2
0
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
示例#3
0
文件: test_env.py 项目: yazici/graft
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
示例#4
0
文件: test_env.py 项目: yazici/graft
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")
示例#5
0
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))
示例#6
0
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)
示例#7
0
def make_env():
    ret = ProgramEnv(Env(), None, None, eval_cell)
    make_graft_env.add_cell_symbols(ret)
    return ret
示例#8
0
文件: test_env.py 项目: yazici/graft
def test_Getting_a_name_after_setting_returns_its_value():
    env = Env()
    env.set("mythree", 3)
    assert env.get("mythree") == 3
示例#9
0
文件: test_env.py 项目: yazici/graft
def test_After_setting_a_name_Env_contains_it():
    env = Env()
    env.set("myname", "foo")
    assert env.contains("myname")
    assert not env.contains("othername")
示例#10
0
文件: test_env.py 项目: yazici/graft
def test_Empty_Env_does_not_contain_names():
    env = Env()
    assert not env.contains("x")