@@ -660,6 +660,32 @@ def test_remove_last_element() -> bool:
660
660
print (ans )
661
661
return tree == ans
662
662
663
+ def test_remove_right_child () -> bool :
664
+ """Test the remove() method of the tree correctly balances, colors,
665
+ and removes. The tested tree should be the same as in test_insert()
666
+ to rule out any insertion errors.
667
+ This instance should test removing a right-side red child.
668
+ """
669
+ tree = RedBlackTree (0 )
670
+ tree .insert (8 )
671
+ tree .insert (- 8 )
672
+ tree .insert (- 5 )
673
+ tree .insert (- 6 )
674
+ tree .insert (4 )
675
+ tree .insert (12 )
676
+ tree .insert (10 )
677
+ tree .insert (11 )
678
+ tree .remove (12 )
679
+ ans = RedBlackTree (0 , 0 )
680
+ ans .left = RedBlackTree (- 6 , 0 , ans )
681
+ ans .left .left = RedBlackTree (- 8 , 1 , ans )
682
+ ans .left .right = RedBlackTree (- 5 , 1 , ans )
683
+ ans .right = RedBlackTree (8 , 1 , ans )
684
+ ans .right .left = RedBlackTree (4 , 0 , ans .right )
685
+ ans .right .right = RedBlackTree (11 , 0 , ans .right )
686
+ ans .right .right .left = RedBlackTree (10 , 1 , ans .right .right )
687
+ return tree == ans
688
+
663
689
664
690
def test_insert_and_search () -> bool :
665
691
"""Tests searching through the tree for values."""
@@ -788,6 +814,7 @@ def main() -> None:
788
814
print_results ("Rotating right and left" , test_rotations ())
789
815
print_results ("Inserting" , test_insert ())
790
816
print_results ("Removing" , test_remove ())
817
+ print_results ("Removing right child" , test_remove_right_child ())
791
818
print_results ("Emptying tree" , test_remove_last_element ())
792
819
print_results ("Searching" , test_insert_and_search ())
793
820
print_results ("Deleting" , test_insert_delete ())
@@ -796,7 +823,7 @@ def main() -> None:
796
823
print_results ("Tree traversal" , test_tree_chaining ())
797
824
print ("Testing tree balancing..." )
798
825
print ("This should only be a few seconds." )
799
- # test_insertion_speed()
826
+ test_insertion_speed ()
800
827
print ("Done!" )
801
828
coverageList = list (dict .fromkeys (coverageList ))
802
829
coverageList .sort ()
0 commit comments