예제 #1
0
 def test_trim_tree_7(self):
     test_parent_node = OrderedNodeBase(node_name='test_parent_node')
     test_child_node_1 = OrderedNodeBase(node_name='test_child_node_1')
     test_child_node_2 = OrderedNodeBase(node_name='test_child_node_2')
     test_child_node_3 = OrderedNodeBase(node_name='test_child_node_3')
     test_child_node_4 = OrderedNodeBase(node_name='test_child_node_4')
     test_child_node_5 = OrderedNodeBase(node_name='test_child_node_5')
     test_child_node_6 = OrderedNodeBase(node_name='test_child_node_6')
     test_tree = TreeBase(root=test_parent_node)
     test_tree.add_node(parent_node=test_parent_node,
                        child_node=test_child_node_1)
     test_tree.add_node(parent_node=test_parent_node,
                        child_node=test_child_node_2)
     test_tree.add_node(parent_node=test_child_node_1,
                        child_node=test_child_node_3)
     test_tree.add_node(parent_node=test_child_node_1,
                        child_node=test_child_node_4)
     test_tree.add_node(parent_node=test_child_node_2,
                        child_node=test_child_node_5)
     test_tree.add_node(parent_node=test_child_node_2,
                        child_node=test_child_node_6)
     test_tree.trim_tree(max_capacity=5, from_right=False)
     self.assertListEqual(
         test_tree.bfs_search(), [('test_parent_node', 0),
                                  ('test_child_node_1', 1),
                                  ('test_child_node_2', 1),
                                  ('test_child_node_5', 2),
                                  ('test_child_node_6', 2)])
     self.assertEqual(test_tree.get_num_nodes(), 5)
예제 #2
0
 def test_bfs_search(self):
     test_parent_node = OrderedNodeBase(node_name='test_parent_node')
     test_child_node_1 = OrderedNodeBase(node_name='test_child_node_1')
     test_child_node_2 = OrderedNodeBase(node_name='test_child_node_2')
     test_tree = TreeBase(root=test_parent_node)
     test_tree.add_node(parent_node=test_parent_node,
                        child_node=test_child_node_1)
     test_tree.add_node(parent_node=test_parent_node,
                        child_node=test_child_node_2)
     self.assertListEqual(test_tree.bfs_search(max_num_node=-1),
                          [('test_parent_node', 0),
                           ('test_child_node_1', 1),
                           ('test_child_node_2', 1)])
     self.assertListEqual(test_tree.bfs_search(max_num_node=2),
                          [('test_parent_node', 0),
                           ('test_child_node_1', 1)])
예제 #3
0
 def test_trim_tree_2(self):
     test_parent_node = OrderedNodeBase(node_name='test_parent_node')
     test_child_node_1 = OrderedNodeBase(node_name='test_child_node_1')
     test_child_node_2 = OrderedNodeBase(node_name='test_child_node_2')
     test_tree = TreeBase(root=test_parent_node)
     test_tree.add_node(parent_node=test_parent_node,
                        child_node=test_child_node_1)
     test_tree.add_node(parent_node=test_child_node_1,
                        child_node=test_child_node_2)
     test_tree.trim_tree(max_capacity=2)
     self.assertListEqual(test_tree.bfs_search(),
                          [('test_parent_node', 0),
                           ('test_child_node_1', 1)])
     self.assertEqual(test_tree.get_num_nodes(), 2)