Tests the three different tree traversal functions.
()
| 655 | |
| 656 | |
| 657 | def test_tree_traversal() -> bool: |
| 658 | """Tests the three different tree traversal functions.""" |
| 659 | tree = RedBlackTree(0) |
| 660 | tree = tree.insert(-16) |
| 661 | tree.insert(16) |
| 662 | tree.insert(8) |
| 663 | tree.insert(24) |
| 664 | tree.insert(20) |
| 665 | tree.insert(22) |
| 666 | if list(tree.inorder_traverse()) != [-16, 0, 8, 16, 20, 22, 24]: |
| 667 | return False |
| 668 | if list(tree.preorder_traverse()) != [0, -16, 16, 8, 22, 20, 24]: |
| 669 | return False |
| 670 | return list(tree.postorder_traverse()) == [-16, 8, 20, 24, 22, 16, 0] |
| 671 | |
| 672 | |
| 673 | def test_tree_chaining() -> bool: |
no test coverage detected