emilydolson / emilydolson/python-red-black-trees

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

Open
#15 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
28
Forks
5
PR merge metrics
No merged PRs in 30d

Description

```
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.