Skip to content

The validity check in the test file misses an important case. #15

Description

@Beakerboy
def test_tree_check() -> None:
    bst = RedBlackTree()
    two = Node(2)
    bst._root = two
    two._red = False
    one = Node(1)
    one.parent = two
    one._red = False
    two.left = one
    three = Node(3)
    three.parent = two
    three._red = False
    two.right = three
    four = Node(4)
    four.parent = three
    three.right = four
    zero = Node(0)
    zero.parent = three
    three.left = zero
    check_valid(bst)

The root is 2, and 0 is to the left of three, but 0 should be on the left of 1. The current checking code just ensures that children are on the correct side of the immediate parent, but not that their location is correct relative to grandparents or higher.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions