本文整理汇总了Python中testlib.new_digraph函数的典型用法代码示例。如果您正苦于以下问题:Python new_digraph函数的具体用法?Python new_digraph怎么用?Python new_digraph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了new_digraph函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_add_digraph
def test_add_digraph(self):
gr1 = testlib.new_digraph()
gr2 = testlib.new_digraph()
gr1.add_graph(gr2)
for each in gr2.nodes():
self.assertTrue(each in gr1)
for each in gr2.edges():
self.assertTrue(each in gr1.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:8,代码来源:unittests-digraph.py
示例2: test_add_empty_digraph
def test_add_empty_digraph(self):
gr1 = testlib.new_digraph()
gr1c = copy(gr1)
gr2 = digraph()
gr1.add_graph(gr2)
self.assertTrue(gr1.nodes() == gr1c.nodes())
self.assertTrue(gr1.edges() == gr1c.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-digraph.py
示例3: test_reverse_digraph
def test_reverse_digraph(self):
gr = testlib.new_digraph()
rev = gr.reverse()
for (u, v) in gr.edges():
self.assertTrue((v, u) in rev.edges())
for (u, v) in rev.edges():
self.assertTrue((v, u) in gr.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-digraph.py
示例4: test_invert_digraph
def test_invert_digraph(self):
gr = testlib.new_digraph()
inv = gr.inverse()
for each in gr.edges():
self.assertTrue(each not in inv.edges())
for each in inv.edges():
self.assertTrue(each not in gr.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-digraph.py
示例5: test_shortest_path_on_digraph
def test_shortest_path_on_digraph(self):
# Test stub: not checking for correctness yet
gr = testlib.new_digraph(wt_range=(1,10))
st, dist = shortest_path(gr, 0)
for each in gr:
if (each in dist):
assert bf_path(gr, 0, each, dist[each])
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-minmax.py
示例6: test_dot_xml_digraph
def test_dot_xml_digraph(self):
gr = testlib.new_digraph()
dotstr = markup.write(gr)
gr1 = markup.read(dotstr)
dotstr = markup.write(gr1)
gr2 = markup.read(dotstr)
graph_equality(gr1, gr2)
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-readwrite.py
示例7: test_dot_for_digraph
def test_dot_for_digraph(self):
gr = testlib.new_digraph()
dotstr = dot.write(gr)
gr1 = dot.read(dotstr)
dotstr = dot.write(gr1)
gr2 = dot.read(dotstr)
graph_equality(gr1, gr2)
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-readwrite.py
示例8: test_remove_node
def test_remove_node(self):
gr = testlib.new_digraph()
gr.del_node(0)
self.assertTrue(0 not in gr)
for each, other in gr.edges():
self.assertTrue(each in gr)
self.assertTrue(other in gr)
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-digraph.py
示例9: test_bfs_in_digraph
def test_bfs_in_digraph(self):
gr = testlib.new_digraph()
st, lo = breadth_first_search(gr)
for each in gr:
if (st[each] != None):
assert lo.index(each) > lo.index(st[each])
for node in st:
assert gr.has_edge((st[node], node)) or st[node] == None
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:8,代码来源:unittests-searching.py
示例10: test_bfs_in_digraph
def test_bfs_in_digraph(self):
gr = testlib.new_digraph()
gr.add_node('find-me')
gr.add_edge((0, 'find-me'))
st, lo = breadth_first_search(gr, root=0, filter=find('find-me'))
assert st['find-me'] == 0
for each in st:
assert st[each] == None or st[each] == 0 or st[st[each]] == 0
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:8,代码来源:unittests-filters.py
示例11: test_dfs_in_digraph
def test_dfs_in_digraph(self):
gr = testlib.new_digraph()
st, pre, post = depth_first_search(gr)
for each in gr:
if (st[each] != None):
assert pre.index(each) > pre.index(st[each])
assert post.index(each) < post.index(st[each])
for node in st:
assert gr.has_edge((st[node], node)) or st[node] == None
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:9,代码来源:unittests-searching.py
示例12: test_dfs_in_digraph
def test_dfs_in_digraph(self):
gr = testlib.new_digraph()
gr.add_node('find-me')
gr.add_node('dont-find-me')
gr.add_edge((0, 'find-me'))
gr.add_edge(('find-me','dont-find-me'))
st, pre, post = depth_first_search(gr, root=0, filter=find('find-me'))
assert st['find-me'] == 0
assert 'dont-find-me' not in st
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:9,代码来源:unittests-filters.py
示例13: test_xml_digraph
def test_xml_digraph(self):
gr = testlib.new_digraph()
dotstr = markup.write(gr)
gr1 = markup.read(dotstr)
dotstr = markup.write(gr1)
gr2 = markup.read(dotstr)
graph_equality(gr1, gr2)
assert len(gr.nodes()) == len(gr1.nodes())
assert len(gr.edges()) == len(gr1.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:9,代码来源:unittests-readwrite.py
示例14: test_dot_for_digraph
def test_dot_for_digraph(self):
gr = testlib.new_digraph()
dotstr = dot.write(gr)
gr1 = dot.read(dotstr)
dotstr = dot.write(gr1)
gr2 = dot.read(dotstr)
graph_equality(gr1, gr2)
assert len(gr.nodes()) == len(gr1.nodes())
assert len(gr.edges()) == len(gr1.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:9,代码来源:unittests-readwrite.py
示例15: test_output_names_in_dot
def test_output_names_in_dot(self):
gr1 = testlib.new_graph()
gr1.name = "Some name 1"
gr2 = testlib.new_digraph()
gr2.name = "Some name 2"
gr3 = testlib.new_hypergraph()
gr3.name = "Some name 3"
assert "Some name 1" in dot.write(gr1)
assert "Some name 2" in dot.write(gr2)
assert "Some name 3" in dot.write(gr3)
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:10,代码来源:unittests-readwrite.py
示例16: test_pagerank_random
def test_pagerank_random(self):
G = testlib.new_digraph()
md = 0.00001
df = 0.85
pr = pagerank(G, damping_factor=df, min_delta=md)
min_value = (1.0-df)/len(G)
for node in G:
expected = min_value
for each in G.incidents(node):
expected += (df * pr[each] / len(G.neighbors(each)))
assert abs(pr[node] - expected) < md
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:11,代码来源:unittests-pagerank.py
示例17: test_mutual_accessibility_in_digraph
def test_mutual_accessibility_in_digraph(self):
gr = testlib.new_digraph()
ma = mutual_accessibility(gr)
for n in gr:
for m in gr:
if (m in ma[n]):
assert m in depth_first_search(gr, n)[0]
assert n in depth_first_search(gr, m)[0]
else:
assert m not in depth_first_search(gr, n)[0] or n not in depth_first_search(gr, m)[0]
开发者ID:svn2github,项目名称:python-graph2,代码行数:11,代码来源:unittests-accessibility.py
示例18: test_accessibility_in_digraph
def test_accessibility_in_digraph(self):
gr = testlib.new_digraph()
gr.add_nodes(['a','b','c'])
gr.add_edge(('a','b'))
gr.add_edge(('a','c'))
ac = accessibility(gr)
for n in gr:
for m in gr:
if (m in ac[n]):
assert m in depth_first_search(gr, n)[0]
else:
assert m not in depth_first_search(gr, n)[0]
开发者ID:svn2github,项目名称:python-graph2,代码行数:14,代码来源:unittests-accessibility.py
示例19: test_mutual_accessibility_in_digraph
def test_mutual_accessibility_in_digraph(self):
gr = testlib.new_digraph()
gr.add_nodes(['a','b','c'])
gr.add_edge(('a','b'))
gr.add_edge(('b','a'))
gr.add_edge(('a','c'))
ma = mutual_accessibility(gr)
for n in gr:
for m in gr:
if (m in ma[n]):
assert m in depth_first_search(gr, n)[0]
assert n in depth_first_search(gr, m)[0]
else:
assert m not in depth_first_search(gr, n)[0] or n not in depth_first_search(gr, m)[0]
开发者ID:svn2github,项目名称:python-graph2,代码行数:15,代码来源:unittests-accessibility.py
示例20: test_topological_sorting_on_digraph
def test_topological_sorting_on_digraph(self):
def is_ordered(node, list):
# Has parent on list
for each in list:
if gr.has_edge(each, node):
return True
# Has no possible ancestors on list
st, pre, post = depth_first_search(gr, node)
for each in list:
if (each in st):
return False
return True
gr = testlib.new_digraph()
ts = topological_sorting(gr)
while (ts):
x = ts.pop()
assert is_ordered(x, ts)
开发者ID:svn2github,项目名称:python-graph2,代码行数:20,代码来源:unittests-sorting.py
注:本文中的testlib.new_digraph函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论