def test_giant_deserialize_preorder_inorder(giant_tree):
    """Writes the tree into two files and checks if they can be read back to
    create the same tree."""
    giant_tree.save_to_disk("giant_tree")

    deserialized_tree = TreeNode.parse_files(preorder="giant_tree.preorder",
                                             inorder="giant_tree.inorder")

    assert isinstance(deserialized_tree, TreeNode)

    assert TreeNode.traverse(deserialized_tree) == TreeNode.traverse(
        giant_tree)
def test_basic_deserialize_preorder_inorder(basic_tree):
    """Writes the tree into two files and checks if they can be read back to
    create the same tree."""
    basic_tree.save_to_disk("basic_tree")

    deserialized_tree = TreeNode.parse_files(preorder="basic_tree.preorder",
                                             inorder="basic_tree.inorder")

    assert TreeNode.traverse(basic_tree, mode="preorder") == TreeNode.traverse(
        deserialized_tree, mode="preorder")

    assert TreeNode.traverse(
        basic_tree, mode="postorder") == TreeNode.traverse(deserialized_tree,
                                                           mode="postorder")

    assert TreeNode.traverse(basic_tree, mode="inorder") == TreeNode.traverse(
        deserialized_tree, mode="inorder")
def test_longer_deserialize_postorder_inorder(longer_tree):
    """Writes the tree into two files and checks if they can be read back to
    create the same tree."""
    longer_tree.save_to_disk("longer_tree",
                             postorder=True,
                             preorder=False,
                             inorder=True)

    deserialized_tree = TreeNode.parse_files(postorder="longer_tree.postorder",
                                             inorder="longer_tree.inorder")

    assert TreeNode.traverse(
        longer_tree, mode="preorder") == TreeNode.traverse(deserialized_tree,
                                                           mode="preorder")

    assert TreeNode.traverse(
        longer_tree, mode="postorder") == TreeNode.traverse(deserialized_tree,
                                                            mode="postorder")

    assert TreeNode.traverse(longer_tree, mode="inorder") == TreeNode.traverse(
        deserialized_tree, mode="inorder")