def test_tree_hash(): tpl = (1, [ (2, []), ]) tree = Tree.from_tuple(tpl) # Check behavior for non-frozen tree with pytest.raises(AssertionError): _h = hash(tree) # Check default behavior tree.freeze() assert isinstance(hash(tree), int) # Check hash equality of equal trees initialized_tree = Tree(value=1, children=(Tree(value=2), )) initialized_tree.freeze() assert hash(tree) == hash(initialized_tree) # Check hash equality of extended equal trees tree = Tree.from_tuple(tpl) tree.insert((0, 0), Tree(value=3)) tree.freeze() initialized_tree = Tree.from_tuple(tpl) initialized_tree.append(Tree(value=3)) initialized_tree.freeze() assert hash(tree) == hash(initialized_tree)
def test_tree_append(): tpl = (1, [(2, []), (4, [])]) tree = Tree(value=1, children=(Tree(value=2, children=()), )) # Check for default behavior tree.append(Tree(value=4, children=())) assert tree == Tree.from_tuple(tpl) # Check append behavior for a frozen tree tree.freeze() with pytest.raises(AssertionError): tree.append(Tree(value=1))