Beispiel #1
0
 def test_avl_unbalanced_with_insertion_becomes_balanced_case_ii(self):
     values_list = [1, 2, 3]
     """
         1
           2
             3
     becomes:
         2
       1   3
     """
     avl_tree = AVLTree()
     avl_tree.insert_list(values_list)
     self.assertEquals(avl_tree.is_balanced(), True)
 def test_avl_unbalanced_with_insertion_becomes_balanced_case_ii(self):
     values_list = [1, 2, 3]
     """
         1
           2
             3
     becomes:
         2
       1   3
     """
     avl_tree = AVLTree()
     avl_tree.insert_list(values_list)
     self.assertEquals(avl_tree.is_balanced(), True)
Beispiel #3
0
    def test_avl_unbalanced_with_insertion_becomes_balanced_case_iv(self):
        values_list = [7, 9, 8]
        """
           7
             9
            8
        becomes:
          8
        7   9
        """

        avl_tree = AVLTree()
        avl_tree.insert_list(values_list)
        self.assertEquals(avl_tree.is_balanced(), True)
Beispiel #4
0
    def test_avl_unbalanced_with_insertion_becomes_balanced_case_iii(self):
        values_list = [6, 4, 5]
        """
           6
        4
         5
        becomes:
          5
        4   6
        """

        avl_tree = AVLTree()
        avl_tree.insert_list(values_list)
        self.assertEquals(avl_tree.is_balanced(), True)
    def test_avl_unbalanced_with_insertion_becomes_balanced_case_iv(self):
        values_list = [7, 9, 8]
        """
           7
             9
            8
        becomes:
          8
        7   9
        """

        avl_tree = AVLTree()
        avl_tree.insert_list(values_list)
        self.assertEquals(avl_tree.is_balanced(), True)
    def test_avl_unbalanced_with_insertion_becomes_balanced_case_iii(self):
        values_list = [6, 4, 5]
        """
           6
        4
         5
        becomes:
          5
        4   6
        """

        avl_tree = AVLTree()
        avl_tree.insert_list(values_list)
        self.assertEquals(avl_tree.is_balanced(), True)
    def test_avl_unbalanced_with_insertion_becomes_balanced_case_i_complex(self):
        values_list = [73, 31, 94, 7, 64, 76, 98, 3, 23, 60, 2]
        """
        given the AVL tree:
                    73
              31         94
           7      64   76   98
         3  23  60

        + node 2 becomes:

                31
           7          73
         3  23      64   94
        2         60    76 98
        """
        avl_tree = AVLTree()
        avl_tree.insert_list(values_list)
        self.assertEquals(avl_tree.is_balanced(), True)
Beispiel #8
0
    def test_avl_unbalanced_with_insertion_becomes_balanced_case_i_complex(
            self):
        values_list = [73, 31, 94, 7, 64, 76, 98, 3, 23, 60, 2]
        """
        given the AVL tree:
                    73
              31         94
           7      64   76   98
         3  23  60

        + node 2 becomes:

                31
           7          73
         3  23      64   94
        2         60    76 98
        """
        avl_tree = AVLTree()
        avl_tree.insert_list(values_list)
        self.assertEquals(avl_tree.is_balanced(), True)
    def test_avl_node_removal_complex(self):
        values_list = [35, 19, 62, 5, 24, 61, 86, 4, 6, 22, 28, 94, 20, 23, 26, 30]
        """
        given the AVL tree:
                      35
                19           62
           5        24     61   86
         4   6   22   28          94
               20 23 26 30

        - node 94 becomes:

                  24
            19           35
         5    22      28    62
        4 6  20 23  26 30  61 86
        """
        avl_tree = AVLTree()
        avl_tree.insert_list(values_list)
        self.assertEquals(avl_tree.is_balanced(), True)
Beispiel #10
0
    def test_avl_node_removal_complex(self):
        values_list = [
            35, 19, 62, 5, 24, 61, 86, 4, 6, 22, 28, 94, 20, 23, 26, 30
        ]
        """
        given the AVL tree:
                      35
                19           62
           5        24     61   86
         4   6   22   28          94
               20 23 26 30

        - node 94 becomes:

                  24
            19           35
         5    22      28    62
        4 6  20 23  26 30  61 86
        """
        avl_tree = AVLTree()
        avl_tree.insert_list(values_list)
        self.assertEquals(avl_tree.is_balanced(), True)
Beispiel #11
0
 def test_avl_with_two_keys_is_balanced(self):
     values_list = [1, 2]
     avl_tree = AVLTree()
     avl_tree.insert_list(values_list)
     self.assertEquals(avl_tree.is_balanced(), True)
Beispiel #12
0
 def test_avl_with_one_key_is_balanced(self):
     avl_tree = AVLTree()
     avl_tree.insert(1)
     self.assertEquals(avl_tree.is_balanced(), True)
Beispiel #13
0
 def test_empty_avl_is_balanced(self):
     avl_tree = AVLTree()
     self.assertEquals(avl_tree.is_balanced(), True)
 def test_avl_with_two_keys_is_balanced(self):
     values_list = [1, 2]
     avl_tree = AVLTree()
     avl_tree.insert_list(values_list)
     self.assertEquals(avl_tree.is_balanced(), True)
 def test_avl_with_one_key_is_balanced(self):
     avl_tree = AVLTree()
     avl_tree.insert(1)
     self.assertEquals(avl_tree.is_balanced(), True)
 def test_empty_avl_is_balanced(self):
     avl_tree = AVLTree()
     self.assertEquals(avl_tree.is_balanced(), True)