Пример #1
0
    def test_search_node(self):
        tree = Tree()
        for val in [7, 3, 6, 9, 11, 5, 2, 8]:
            tree.add_value(val)
        result = tree.search(9)
        expected_node = Node(9)
        expected_node.add_node(Node(8))
        expected_node.add_node(Node(11))

        self.assertEqual(result, expected_node)
Пример #2
0
 def test_node_depth(self):
     tree = Tree()
     for val in [7, 3, 6, 9, 11, 5, 2, 8, 13, 15, 12, 10, 14]:
         tree.add_value(val)
     result = tree.depth(14)
     self.assertEqual(result, 5)
Пример #3
0
 def test_node_height(self):
     tree = Tree()
     for val in [7, 3, 6, 9, 11, 5, 2, 8, 13, 15, 12, 10, 14]:
         tree.add_value(val)
     result = tree.height(9)
     self.assertEqual(result, 4)
Пример #4
0
 def test_tree_level(self):
     tree = Tree()
     for val in [7, 3, 6, 9, 11, 5, 2, 8]:
         tree.add_value(val)
     result = tree.level()
     self.assertEqual(result, 3)
Пример #5
0
 def test_node_degree(self):
     tree = Tree()
     for val in [7, 3, 6, 9, 11, 5, 2, 8]:
         tree.add_value(val)
     result = tree.degree(6)
     self.assertEqual(result, 1)
Пример #6
0
 def test_internal_nodes(self):
     tree = Tree()
     for val in [7, 3, 6, 9, 11, 5, 2, 8]:
         tree.add_value(val)
     result = tree.internal_nodes()
     self.assertEqual(result, [3, 6, 7, 9])
Пример #7
0
 def test_leaf_nodes(self):
     tree = Tree()
     for val in [7, 3, 6, 9, 11, 5, 2, 8]:
         tree.add_value(val)
     result = tree.leaf_nodes()
     self.assertEqual(result, [2, 5, 8, 11])