def test_update_heights(self): node_5 = Node(5) node_0 = Node(0) node_12 = Node(12) tree = AVL(node_5) tree._set_root(node_5) node_5.set_left_child(node_0) node_5.set_right_child(node_12) node_0.set_parent(node_5) node_12.set_parent(node_5) node_5._set_height(1) node_0._set_height(0) node_12._set_height(0) node_6 = Node(6) node_12.set_left_child(node_6) node_6.set_parent(node_12) tree._update_heights(node_6) expect(node_5.get_height()).to.be.equal(2) expect(node_0.get_height()).to.be.equal(0) expect(node_12.get_height()).to.be.equal(1) expect(node_6.get_height()).to.be.equal(0)
def test_rotate_right_subtree_is_right_child_from_root(self): A = create_right_rotable_tree() root = Node(10, name='root') root.set_right_child(A) A.set_parent(root) root._set_height(3) rotable_to_right_tree = AVL(root) rotable_to_right_tree._right_rotate( rotable_to_right_tree.get_root().get_right_child()) root = rotable_to_right_tree.get_root() B = root.get_right_child() A = B.get_right_child() a = B.get_left_child() c = A.get_right_child() b = A.get_left_child() expect(root.get_name()).to.be.equal('root') expect(B.get_name()).to.be.equal('B') expect(A.get_name()).to.be.equal('A') expect(a.get_name()).to.be.equal('a') expect(b.get_name()).to.be.equal('b') expect(c.get_name()).to.be.equal('c') expect(root.get_height()).to.be.equal(3) expect(B.get_height()).to.be.equal(2) expect(A.get_height()).to.be.equal(1) expect(a.get_height()).to.be.equal(0) expect(b.get_height()).to.be.equal(0) expect(c.get_height()).to.be.equal(0) expect(root.get_node_count()).to.be.equal(6) expect(B.get_node_count()).to.be.equal(5) expect(A.get_node_count()).to.be.equal(3) expect(a.get_node_count()).to.be.equal(1) expect(b.get_node_count()).to.be.equal(1) expect(c.get_node_count()).to.be.equal(1)