def test_tree() -> Tree: tree = Tree(name="root", data=0) child1 = Tree(name="child1", data=1) child2 = Tree(name="child2", data=2) child3 = Tree(name="child3", data=3) tree.add_child(child1) tree.add_child(child2) tree.add_child(child3) child1.add_child(Tree(name="child1_child1", data=11)) child2.add_child(Tree(name="child2_child1", data=21)) child2.add_child(Tree(name="child2_child2", data=22)) child3.add_child(Tree(name="child3_child1", data=31)) child3.add_child(Tree(name="child3_child2", data=32)) child3_child3 = Tree(name="child3_child3", data=33) child3.add_child(child3_child3) child3_child3.add_child(Tree(name="child3_child3_child1", data=331)) return tree
def test_find_all_by_name(test_tree: Tree): test_tree.add_child(Tree(name="child1")) assert len(test_tree.find_all_by_name("child1")) == 2
def test_add_child(test_tree: Tree): test_tree.add_child(Tree(name="child4")) assert len(test_tree.children) == 4 assert test_tree.find_one_by_name("child4") == Tree(name="child4")