예제 #1
0
    def test_rotate_left_subtree_with_no_parent(self):
        A = create_left_rotable_tree()

        rotable_to_left_tree = AVL(A)
        rotable_to_left_tree._left_rotate(rotable_to_left_tree.get_root())

        B = rotable_to_left_tree.get_root()
        a = B.get_right_child()
        A = B.get_left_child()
        b = A.get_right_child()
        c = A.get_left_child()

        expect(B.get_name()).to.be.equal('B')
        expect(A.get_name()).to.be.equal('A')
        expect(c.get_name()).to.be.equal('c')
        expect(a.get_name()).to.be.equal('a')
        expect(b.get_name()).to.be.equal('b')

        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(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)
예제 #2
0
    def test_rotate_left_subtree_is_left_child_from_root(self):
        A = create_left_rotable_tree()

        root = Node(10, name='root')
        root.set_left_child(A)
        A.set_parent(root)

        rotable_to_left_tree = AVL(root)
        rotable_to_left_tree._left_rotate(
            rotable_to_left_tree.get_root().get_left_child())

        root = rotable_to_left_tree.get_root()
        B = root.get_left_child()
        a = B.get_right_child()
        A = B.get_left_child()
        b = A.get_right_child()
        c = 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(c.get_name()).to.be.equal('c')
        expect(a.get_name()).to.be.equal('a')
        expect(b.get_name()).to.be.equal('b')

        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)