File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
data_structures/binary_tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -646,6 +646,20 @@ def test_remove() -> bool:
646
646
ans .right .right .right = RedBlackTree (12 , 1 , ans .right .right )
647
647
return tree == ans
648
648
649
+ def test_remove_last_element () -> bool :
650
+ """Test the remove() method of the tree correctly removes
651
+ the final element in a tree. Afterwards, the tree should be
652
+ empty.
653
+ """
654
+ tree = RedBlackTree (0 )
655
+ tree .insert (8 )
656
+ tree .remove (0 )
657
+ tree .remove (8 )
658
+ print (tree )
659
+ ans = RedBlackTree (None )
660
+ print (ans )
661
+ return tree == ans
662
+
649
663
650
664
def test_insert_and_search () -> bool :
651
665
"""Tests searching through the tree for values."""
@@ -774,6 +788,7 @@ def main() -> None:
774
788
print_results ("Rotating right and left" , test_rotations ())
775
789
print_results ("Inserting" , test_insert ())
776
790
print_results ("Removing" , test_remove ())
791
+ print_results ("Emptying tree" , test_remove_last_element ())
777
792
print_results ("Searching" , test_insert_and_search ())
778
793
print_results ("Deleting" , test_insert_delete ())
779
794
print_results ("Floor and ceil" , test_floor_ceil ())
You can’t perform that action at this time.
0 commit comments