当前位置: 首页>>代码示例>>Python>>正文


Python Tree.search方法代码示例

本文整理汇总了Python中tree.Tree.search方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.search方法的具体用法?Python Tree.search怎么用?Python Tree.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree.Tree的用法示例。


在下文中一共展示了Tree.search方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSearch

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import search [as 别名]
    def testSearch(self):
        tree = Tree()
        for word in insert_queue:
            tree.insert(word)

        for i in insert_queue:
            self.assertEqual(tree.search(i), i)

        self.assertEqual(tree.search("not found"), None)
开发者ID:theevocater,项目名称:pydatastructures,代码行数:11,代码来源:test.py

示例2: test_new_tree_add_2_nodes_and_search_it

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import search [as 别名]
 def test_new_tree_add_2_nodes_and_search_it(self):
     t = Tree()
     n = Node(title='test', id='1', parent_id='root')
     t.add(n)
     n = Node(title='test2', id='2', parent_id='1')
     t.add(n)
     #print(t)
     result = t.search('2')
     self.assertEqual(result.get_id(), '2')
开发者ID:mkgilbert,项目名称:GDriveMgr,代码行数:11,代码来源:test_tree.py

示例3: testDelete

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import search [as 别名]
    def testDelete(self):
        tree = Tree()
        copy_q = copy(insert_queue)
        for word in copy_q:
            tree.insert(word)

        tree.delete(copy_q[-1])
        self.assertEqual(tree.search(copy_q[-1]), None)

        copy_q.pop()
        copy_q.sort()
        self.assertEqual(tree.inorder_traverse(), " ".join(copy_q))
开发者ID:theevocater,项目名称:pydatastructures,代码行数:14,代码来源:test.py

示例4: TestTreeMethods

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import search [as 别名]
class TestTreeMethods(unittest.TestCase):
    
    def setUp(self):
        self.n1 = Node(title='node1', id='1', parent_id='root')
        self.n2 = Node(title='node2', id='2', parent_id='1')
        self.n3 = Node(title='node3', id='3', parent_id='1')
        self.n4 = Node(title='node4', id='4', parent_id='2')
        self.n5 = Node(title='node5', id='5', parent_id='4') 
        
        # set up tree with multiple nodes
        self.t1 = Tree()
        self.t1.add(self.n1) # node1 has many children
        self.t1.add(self.n2)
        self.t1.add(self.n3)
        self.t1.add(self.n4)
        self.t1.add(self.n5)
        #print("Tree before the test:")
        #print(self.t1)
        
        # set up tree with only one node besides root
        self.n6 = Node('node6', '6', parent_id='root')
        self.one_node_tree = Tree()
        self.one_node_tree.add(self.n6)

    def tearDown(self):
        self.n1 = None
        self.n2 = None
        self.n3 = None
        self.n4 = None
        self.n5 = None
        self.n6 = None
        self.t1 = None
        self.t2 = None

    def test_get_root(self):
        self.assertEqual(self.t1.get_root().get_id(), 'root')

    def test_init_node_not_have_id_root(self):
        """ test init using a node who's id is not 'root'"""
        n = Node(title='foo', id=0)
        t = Tree(n)
        self.assertEqual(t.get_root().get_id(), 'root')

    def test_init_node_has_id_of_root(self):
        n = Node(title='foo', id='root')
        t = Tree(n)
        self.assertEqual(t.get_root().get_id(), 'root')
    
    def test_string_empty_tree(self):
        t2 = Tree(None)
        self.assertEqual(t2.__str__(), '|---Google_Drive\n')

    def test_string_non_empty_tree(self):
        print("You can't really test this...automatically")
        print(self.t1)

    def test_search_for_root(self):
        result = self.t1.search('root')
        self.assertTrue(result.get_id() == 'root')

    def test_search_for_first_node_added(self):
        result = self.t1.search('1')
        self.assertTrue(result.get_id() == '1')

    def test_search_for_nonexisting_node_in_one_node_tree(self):
        result = self.one_node_tree.search(self.n2.get_id())
        self.assertTrue(result == None)
    
    def test_new_tree_add_2_nodes_and_print_it(self):
        t = Tree()
        n = Node(title='test', id='1', parent_id='root')
        t.add(n)
        n = Node(title='test2', id='2', parent_id='1')
        t.add(n)
        print(t)

    def test_new_tree_add_2_nodes_and_search_it(self):
        t = Tree()
        n = Node(title='test', id='1', parent_id='root')
        t.add(n)
        n = Node(title='test2', id='2', parent_id='1')
        t.add(n)
        #print(t)
        result = t.search('2')
        self.assertEqual(result.get_id(), '2')

# From here down, tests are failing
    def test_search_for_nested_leaf_node(self):
        result = self.t1.search(self.n5.get_id())
        self.assertTrue('5' == result.get_id())

    def test_search_for_node1(self):
        result = self.t1.search(self.n1.get_id())
        self.assertTrue(result.get_id(), '1')

    def test_search_for_node2(self):
        result = self.t1.search(self.n2.get_id())
        self.assertTrue(result.get_id(), '2')

    def test_search_for_node3(self):
#.........这里部分代码省略.........
开发者ID:mkgilbert,项目名称:GDriveMgr,代码行数:103,代码来源:test_tree.py

示例5: test_search_empty_tree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import search [as 别名]
 def test_search_empty_tree(self):
     root = None
     empty_tree = Tree(root)
     result = empty_tree.search(self.n1.get_id())
     self.assertEqual(result, None)
开发者ID:mkgilbert,项目名称:GDriveMgr,代码行数:7,代码来源:test_tree.py


注:本文中的tree.Tree.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。