本文整理汇总了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')
示例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')
示例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)+"}}"
示例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"))
示例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))
示例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)