def test_findmin(self):
     a = Node(5)
     for i in range(1, 4):
         a = Node.insert(a, i)
     for i in range(6, 9):
         a = Node.insert(a, i)
     self.assertEqual(1, Node.findmin(a).key)
 def test_remove_2(self):
     a = Node(1)
     for i in range(2, 9):
         a = Node.insert(a, i)
     self.assertEqual(True, Node.containskey(a, 6))
     a = Node.remove(a, 6)
     self.assertEqual(False, Node.containskey(a, 6))
 def test_dfs(self):
     a = Node(1)
     for i in range(2, 10):
         a = Node.insert(a, i)
     result_list = []
     Node.dfs(a, result_list)
     self.assertEqual([1, 3, 2, 5, 7, 9, 8, 6, 4], result_list)
    def remove_node(self):
        self.clear_error()
        Node.remove(self.root_node, self.input_value)

        result_list = []
        Node.dfs(self.root_node, result_list)
        self.output_value = result_list
Exemplo n.º 5
0
 def remove_node(self):
     self.clear_error()
     self.logger.log('Trying to remove node with number {}'.format(
         self.input_value))
     self.root_node = Node.remove(self.root_node, self.input_value)
     result_list = []
     Node.dfs(self.root_node, result_list)
     self.output_value = result_list
     self.logger.log('Node removed successfully')
    def add_node(self):
        try:
            self.clear_error()
            if self.root_node is None:
                self.root_node = Node(self.input_value)
            else:
                Node.insert(self.root_node, self.input_value)

            result_list = []
            Node.dfs(self.root_node, result_list)
            self.output_value = result_list

        except ValueError:
            self.error = "Please enter numeric positive value"
Exemplo n.º 7
0
    def add_node(self):
        try:
            self.clear_error()
            self.logger.log('Trying to add node with number {}'.format(
                self.input_value))
            if self.root_node is None:
                self.root_node = Node(self.input_value)
            else:
                self.root_node = Node.insert(self.root_node, self.input_value)

            result_list = []
            Node.dfs(self.root_node, result_list)
            self.output_value = result_list
            self.logger.log('Node added successfully')

        except ValueError:
            self.error = "Please enter numeric positive value"
            self.log_message = "Error occurred: {}".format(self.error)
 def test_bfactor(self):
     a = Node(1)
     a = Node.insert(a, 2)
     self.assertEquals(1, Node.bfactor(a))
 def test_insert_both_sides(self):
     a = Node(3)
     a = Node.insert(a, 4)
     a = Node.insert(a, 2)
     self.assertIsNotNone(a.right)
     self.assertIsNotNone(a.left)
 def test_contains_none(self):
     a = Node(1)
     for i in range(3, 9):
         a = Node.insert(a, i)
     self.assertEqual(False, Node.containskey(None, 2))
 def test_fixheight(self):
     a = Node(1)
     a = Node.insert(a, 2)
     Node.fixheight(a)
     self.assertEqual(2, Node.height(a))
 def test_height(self):
     a = Node(1)
     self.assertEqual(1, Node.height(a))
 def test_contains_true(self):
     a = Node(1)
     for i in range(3, 9):
         a = Node.insert(a, i)
     self.assertEqual(True, Node.containskey(a, 6))
 def test_rotate_left(self):
     a = Node(1)
     a = Node.insert(a, 2)
     a = Node.rotateleft(a)
     self.assertEqual(2, a.key)
     self.assertEqual(1, a.left.key)
 def test_height_2(self):
     a = Node(3)
     a = Node.insert(a, 2)
     self.assertEqual(2, Node.height(a))
 def test_rotate_right(self):
     a = Node(2)
     a = Node.insert(a, 1)
     a = Node.rotateright(a)
     self.assertEqual(1, a.key)
     self.assertEqual(2, a.right.key)
 def test_balance_left(self):
     a = Node(3)
     a.left = Node(2)
     a.left.left = Node(1)
     a.right = Node(4)
     Node.fixheight(a.left.left)
     Node.fixheight(a.left)
     Node.fixheight(a)
     Node.fixheight(a.right)
     Node.balance(a.left.left)
     self.assertEqual(-1, Node.bfactor(a))
 def test_insert_right(self):
     a = Node(3)
     a = Node.insert(a, 4)
     self.assertIsNotNone(a.right)
     self.assertIsNone(a.left)
 def test_balance(self):
     a = Node(2)
     a.left = Node(1)
     a.right = Node(3)
     a.right.right = Node(4)
     a.right.left = Node(5)
     a.right.height = 3
     a.left.height = 1
     a.right.right.height = 4
     a.right.left.height = 5
     Node.balance(a)
     self.assertEqual(-1, Node.bfactor(a))
 def test_remove_no_key(self):
     self.assertEqual(0, Node.remove(None, 3))