MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / test_insert_delete

Function test_insert_delete

data_structures/binary_tree/red_black_tree.py:607–626  ·  view source on GitHub ↗

Test the insert() and delete() method of the tree, verifying the insertion and removal of elements, and the balancing of the tree.

()

Source from the content-addressed store, hash-verified

605
606
607def test_insert_delete() -> bool:
608 """Test the insert() and delete() method of the tree, verifying the
609 insertion and removal of elements, and the balancing of the tree.
610 """
611 tree = RedBlackTree(0)
612 tree = tree.insert(-12)
613 tree = tree.insert(8)
614 tree = tree.insert(-8)
615 tree = tree.insert(15)
616 tree = tree.insert(4)
617 tree = tree.insert(12)
618 tree = tree.insert(10)
619 tree = tree.insert(9)
620 tree = tree.insert(11)
621 tree = tree.remove(15)
622 tree = tree.remove(-12)
623 tree = tree.remove(9)
624 if not tree.check_color_properties():
625 return False
626 return list(tree.inorder_traverse()) == [-8, 0, 4, 8, 10, 11, 12]
627
628
629def test_floor_ceil() -> bool:

Callers 2

pytestsFunction · 0.85
mainFunction · 0.85

Calls 5

insertMethod · 0.95
removeMethod · 0.95
inorder_traverseMethod · 0.95
RedBlackTreeClass · 0.85

Tested by

no test coverage detected