Test the insert() method of the tree correctly balances, colors, and inserts.
()
| 568 | |
| 569 | |
| 570 | def test_insert() -> bool: |
| 571 | """Test the insert() method of the tree correctly balances, colors, |
| 572 | and inserts. |
| 573 | """ |
| 574 | tree = RedBlackTree(0) |
| 575 | tree.insert(8) |
| 576 | tree.insert(-8) |
| 577 | tree.insert(4) |
| 578 | tree.insert(12) |
| 579 | tree.insert(10) |
| 580 | tree.insert(11) |
| 581 | ans = RedBlackTree(0, 0) |
| 582 | ans.left = RedBlackTree(-8, 0, ans) |
| 583 | ans.right = RedBlackTree(8, 1, ans) |
| 584 | ans.right.left = RedBlackTree(4, 0, ans.right) |
| 585 | ans.right.right = RedBlackTree(11, 0, ans.right) |
| 586 | ans.right.right.left = RedBlackTree(10, 1, ans.right.right) |
| 587 | ans.right.right.right = RedBlackTree(12, 1, ans.right.right) |
| 588 | return tree == ans |
| 589 | |
| 590 | |
| 591 | def test_insert_and_search() -> bool: |
no test coverage detected