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

Function test_insert

data_structures/binary_tree/red_black_tree.py:570–588  ·  view source on GitHub ↗

Test the insert() method of the tree correctly balances, colors, and inserts.

()

Source from the content-addressed store, hash-verified

568
569
570def 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
591def test_insert_and_search() -> bool:

Callers 2

pytestsFunction · 0.70
mainFunction · 0.70

Calls 2

insertMethod · 0.95
RedBlackTreeClass · 0.85

Tested by

no test coverage detected