Example #1
0
def test_tree_subs():
    tree = parse((thunk.fromexpr(1) + 2) - 3)
    assert tree.subs({
        Call(Normal(op.add), (Normal(1), Normal(2)), {}): Normal(4)
    }) == Call(Normal(op.sub), (Normal(4), Normal(3)), {})

    other_tree = parse(thunk.fromexpr(1) + 1 + 1)
    assert other_tree.subs({1: 2}) == parse(thunk.fromexpr(2) + 2 + 2)
Example #2
0
def test_tree_subs():
    tree = parse((thunk.fromexpr(1) + 2) - 3)
    assert tree.subs(
        {Call(Normal(op.add), (Normal(1), Normal(2)), {}):
         Normal(4)}) == Call(Normal(op.sub), (Normal(4), Normal(3)), {})

    other_tree = parse(thunk.fromexpr(1) + 1 + 1)
    assert other_tree.subs({1: 2}) == parse(thunk.fromexpr(2) + 2 + 2)
Example #3
0
def test_tree_leaves():
    def f(a):
        return a

    tree = parse(thunk(f, (thunk.fromexpr(1) + 2) - 3))

    assert set(tree.leaves()) == set(map(Normal, (f, op.add, op.sub, 1, 2, 3)))
Example #4
0
def test_tree_leaves():
    def f(a):
        return a

    tree = parse(thunk(f, (thunk.fromexpr(1) + 2) - 3))

    assert set(tree.leaves()) == set(map(Normal, (f, op.add, op.sub, 1, 2, 3)))
Example #5
0
def test_tree_contains():
    tree = parse((thunk.fromexpr(1) + 2) + 3)

    assert 1 in tree
    assert 2 in tree
    assert 3 in tree
    sub = Call(Normal(op.add), (Normal(1), Normal(2)), {})
    assert sub in tree
    assert Call(Normal(op.add), (sub, Normal(3)), {}) in tree
Example #6
0
def test_tree_contains():
    tree = parse((thunk.fromexpr(1) + 2) + 3)

    assert 1 in tree
    assert 2 in tree
    assert 3 in tree
    sub = Call(Normal(op.add), (Normal(1), Normal(2)), {})
    assert sub in tree
    assert Call(Normal(op.add), (sub, Normal(3)), {}) in tree
Example #7
0
def test_tree_hash(expr):
    assert hash(parse(expr())) == hash(parse(expr()))
Example #8
0
def test_tree_eq(expr):
    assert parse(expr()) == parse(expr())
Example #9
0
def test_compile_of_parse_identity(expr):
    assert strict(parse(expr()).lcompile()) == strict(expr())
Example #10
0
def test_tree_hash(expr):
    assert hash(parse(expr())) == hash(parse(expr()))
Example #11
0
def test_tree_eq(expr):
    assert parse(expr()) == parse(expr())
Example #12
0
def test_compile_of_parse_identity(expr):
    assert strict(parse(expr()).lcompile()) == strict(expr())