本文整理汇总了Python中testlib.new_graph函数的典型用法代码示例。如果您正苦于以下问题:Python new_graph函数的具体用法?Python new_graph怎么用?Python new_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了new_graph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_graph
def test_add_graph(self):
gr1 = testlib.new_graph()
gr2 = testlib.new_graph()
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())
示例2: test_shortest_path_should_fail_if_source_does_not_exist
def test_shortest_path_should_fail_if_source_does_not_exist(self):
gr = testlib.new_graph()
try:
shortest_path(gr, 'invalid')
assert False
except (KeyError):
pass
示例3: test_remove_node
def test_remove_node(self):
gr = testlib.new_graph()
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)
示例4: test_invert_graph
def test_invert_graph(self):
gr = testlib.new_graph()
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())
示例5: test_xml_for_graph
def test_xml_for_graph(self):
gr = testlib.new_graph()
dotstr = markup.write(gr)
gr1 = markup.read(dotstr)
dotstr = markup.write(gr1)
gr2 = markup.read(dotstr)
graph_equality(gr1, gr2)
示例6: test_order_len_equivlance
def test_order_len_equivlance(self):
"""
Verify the behavior of G.order()
"""
gr = testlib.new_graph()
assert len(gr) == gr.order()
assert gr.order() == len( gr.node_neighbors )
示例7: test_dot_for_graph
def test_dot_for_graph(self):
gr = testlib.new_graph()
dotstr = dot.write(gr)
gr1 = dot.read(dotstr)
dotstr = dot.write(gr1)
gr2 = dot.read(dotstr)
graph_equality(gr1, gr2)
示例8: test_add_empty_graph
def test_add_empty_graph(self):
gr1 = testlib.new_graph()
gr1c = copy(gr1)
gr2 = graph()
gr1.add_graph(gr2)
self.assertTrue(gr1.nodes() == gr1c.nodes())
self.assertTrue(gr1.edges() == gr1c.edges())
示例9: test_bfs_in_graph
def test_bfs_in_graph(self):
gr = testlib.new_graph()
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
示例10: test_repr
def test_repr(self):
"""
Validate the repr string
"""
gr = testlib.new_graph()
gr_repr = repr(gr)
assert isinstance(gr_repr, str )
assert gr.__class__.__name__ in gr_repr
示例11: test_dfs_in_graph
def test_dfs_in_graph(self):
gr = testlib.new_graph()
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
示例12: test_dfs_in_graph
def test_dfs_in_graph(self):
gr = testlib.new_graph()
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
示例13: test_xml_for_graph
def test_xml_for_graph(self):
gr = testlib.new_graph()
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())
示例14: 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)
示例15: test_connected_components_in_graph
def test_connected_components_in_graph(self):
gr = testlib.new_graph()
gr.add_nodes(['a','b','c'])
gr.add_edge(('a','b'))
cc = connected_components(gr)
for n in gr:
for m in gr:
if (cc[n] == cc[m]):
assert m in depth_first_search(gr, n)[0]
else:
assert m not in depth_first_search(gr, n)[0]