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


Python Tree.find方法代码示例

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


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

示例1: test_exceptions

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import find [as 别名]
    def test_exceptions(self):
        with self.assertRaises(ValueError):
            t = Tree("t", "T")
            t.insert('t', "T")

        with self.assertRaises(KeyError):
            t = Tree('t', "T")
            t.find('z')        
开发者ID:cbabil,项目名称:python-classes,代码行数:10,代码来源:test_tree.py

示例2: test_tree_find

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import find [as 别名]
 def test_tree_find(self):
     'Verify find method, with data and without'
     t = Tree('D')
     for c, i in (('F', [6,7,8]),('C', 3), ('G', dict(one=1, two=2)), ('A', 1), ('E', 5), ('B', 2)):
         t.insert(c, i)
     self.assertEqual(t.find('D'), None)
     self.assertEqual(t.find('A'), 1)
     self.assertEqual(t.find('F'), [6,7,8])
     self.assertEqual(t.find('G'), {'one':1, 'two':2})
     self.assertRaises(KeyError, t.find, 'Z')
开发者ID:rwehner,项目名称:rl,代码行数:12,代码来源:test_tree.py

示例3: arvoreminima

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import find [as 别名]
	def arvoreminima(self):
		"""
			Opera apenas em grafos não-direcionados e conectados
			{"arvoreminima":{"arestas":[(1,2),(2,0),(1,0)], "custo":21}}
		"""

		copy = self.matriz
		edges = []
		menor = [-1,-1,-1]

		teste = False

		out = []
		weight = ''
		for k in range (self.edge/2):
			for i in range (self.size):
				for j in range (i):
					if (copy[i][j] > -1):
						if (int(menor[2]) > int(-1)):
							if (int(copy[i][j]) < int(menor[2])):
								menor = [j,i,copy[i][j]]
								teste = True
						else:
							menor = [j,i,copy[i][j]]
							teste = True

			copy[menor[1]][menor[0]] = -1
			edges += [menor]
			menor = [-1,-1,-1]

		if teste:
			connected = Tree(self.size)
			aux = edges.pop(0)

			weight = aux[2]
			tree = [[aux[0],aux[1]]]

			while (len(tree) < self.size - 1):
				aux = edges.pop(0)

				if (connected.find(aux[0]) != connected.find(aux[1])):
					weight += aux[2]
					tree += [[aux[0],aux[1]]]
					connected.merge(aux[0],aux[1])

			out = "["
			for i in range(len(tree)):
				out += str("(")+str(tree[i][0])+","+str(tree[i][1])+")"
				if (i < (len(tree) - 1)):
					out += str(',')
			out += "]"

		return "{\"arvoreminima\":{\"arestas\":"+str(out)+", \"custo\":"+str(weight)+"}}"
开发者ID:marlonsd,项目名称:EDII-Graph,代码行数:55,代码来源:graph.py

示例4: test_find_returns_node_with_the_specified_value_when_such_exists

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import find [as 别名]
def test_find_returns_node_with_the_specified_value_when_such_exists():
    t = Tree("a")
    t.add_child("b")
    t.add_child("c").add_child("d").add_child("e")

    node = t.find("d")

    assert_that(node.children[0].value, is_("e"))
开发者ID:povilasb,项目名称:pytree,代码行数:10,代码来源:test_tree.py

示例5: Test

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import find [as 别名]
class Test(unittest.TestCase):


    def setUp(self):
        self.test = Tree("D", ord("D"))
        for c in "BJQKFAC":
            self.test.insert(c, ord(c)) 


    def testTree(self):
        self.assertEqual(self.test.answer(70), 'F')
        self.assertEqual(self.test.answer(81), 'Q')
        
    def testExceptions(self):
        self.assertRaises(KeyError, self.test.find(99))
开发者ID:paulrefalo,项目名称:Python-2---4,代码行数:17,代码来源:test_tree.py

示例6: test_find

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import find [as 别名]
 def test_find(self):
     t = Tree('t', "T")
     observed = t.find('t')
     expected = 'T'
     self.assertEqual(observed, expected)
开发者ID:cbabil,项目名称:python-classes,代码行数:7,代码来源:test_tree.py


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