Ejemplo n.º 1
0
    def test_findParent_whenLookingAtLevel1_returnsRoot(self):
        bst = BinarySearchTree()
        bst.insert(10, bst.root)
        bst.insert(9, bst.root)
        bst.insert(15, bst.root)

        self.assertEqual(bst.findParent(9, bst.root).value, 10)
Ejemplo n.º 2
0
    def test_findParent_whenLookingAtRoot_returnsNone(self):
        bst = BinarySearchTree()
        bst.insert(10, bst.root)
        bst.insert(9, bst.root)
        bst.insert(15, bst.root)

        self.assertIsNone(bst.findParent(10, bst.root))
Ejemplo n.º 3
0
    def test_findParent_whenLookingAtLevel2_returnsRightParentFromLevel1(self):
        bst = BinarySearchTree()
        bst.insert(19, bst.root)
        bst.insert(15, bst.root)
        bst.insert(21, bst.root)
        bst.insert(11, bst.root)
        bst.insert(18, bst.root)

        self.assertEqual(bst.findParent(18, bst.root).value, 15)