def test_tree_subs(): tree = LTree.parse((thunk.fromvalue(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 = LTree.parse(thunk.fromvalue(1) + 1 + 1) assert other_tree.subs({1: 2}) == LTree.parse(thunk.fromvalue(2) + 2 + 2)
def test_tree_contains(): tree = LTree.parse((thunk.fromvalue(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
def test_fromvalue_of_thunk(type_): a = thunk.fromvalue(type_.fromvalue(1)) assert isinstance(a, type_) assert isinstance(strict(a), int) assert not isinstance(strict(a), type_)
def test_strict_thunk(): assert strict(thunk.fromvalue(5)) is 5 assert strict(thunk(lambda a: a, 5)) is 5