本文整理汇总了Python中networkx.testing.assert_edges_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_edges_equal函数的具体用法?Python assert_edges_equal怎么用?Python assert_edges_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_edges_equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_project_weighted_shared
def test_project_weighted_shared(self):
edges=[('A','B',2),
('A','C',1),
('B','C',1),
('B','D',1),
('B','E',2),
('E','F',1)]
Panswer=nx.Graph()
Panswer.add_weighted_edges_from(edges)
P=bipartite.weighted_projected_graph(self.G,'ABCDEF')
assert_edges_equal(P.edges(),Panswer.edges())
for u,v in P.edges():
assert_equal(P[u][v]['weight'],Panswer[u][v]['weight'])
edges=[('A','B',3),
('A','E',1),
('A','C',1),
('A','D',1),
('B','E',1),
('B','C',1),
('B','D',1),
('C','D',1)]
Panswer=nx.Graph()
Panswer.add_weighted_edges_from(edges)
P=bipartite.weighted_projected_graph(self.N,'ABCDE')
assert_edges_equal(P.edges(),Panswer.edges())
for u,v in P.edges():
assert_equal(P[u][v]['weight'],Panswer[u][v]['weight'])
示例2: test_project_weighted_jaccard
def test_project_weighted_jaccard(self):
edges = [
("A", "B", 2 / 5.0),
("A", "C", 1 / 2.0),
("B", "C", 1 / 5.0),
("B", "D", 1 / 5.0),
("B", "E", 2 / 6.0),
("E", "F", 1 / 3.0),
]
Panswer = nx.Graph()
Panswer.add_weighted_edges_from(edges)
P = bipartite.overlap_weighted_projected_graph(self.G, "ABCDEF")
assert_edges_equal(P.edges(), Panswer.edges())
for u, v in P.edges():
assert_equal(P[u][v]["weight"], Panswer[u][v]["weight"])
edges = [
("A", "B", 3 / 3.0),
("A", "E", 1 / 3.0),
("A", "C", 1 / 3.0),
("A", "D", 1 / 3.0),
("B", "E", 1 / 3.0),
("B", "C", 1 / 3.0),
("B", "D", 1 / 3.0),
("C", "D", 1 / 1.0),
]
Panswer = nx.Graph()
Panswer.add_weighted_edges_from(edges)
P = bipartite.overlap_weighted_projected_graph(self.N, "ABCDE")
assert_edges_equal(P.edges(), Panswer.edges())
for u, v in P.edges():
assert_equal(P[u][v]["weight"], Panswer[u][v]["weight"])
示例3: test_project_weighted_ratio
def test_project_weighted_ratio(self):
edges=[('A','B',2/6.0),
('A','C',1/6.0),
('B','C',1/6.0),
('B','D',1/6.0),
('B','E',2/6.0),
('E','F',1/6.0)]
Panswer=nx.Graph()
Panswer.add_weighted_edges_from(edges)
P=bipartite.weighted_projected_graph(self.G, 'ABCDEF', ratio=True)
assert_edges_equal(list(P.edges()),Panswer.edges())
for u,v in list(P.edges()):
assert_equal(P[u][v]['weight'],Panswer[u][v]['weight'])
edges=[('A','B',3/3.0),
('A','E',1/3.0),
('A','C',1/3.0),
('A','D',1/3.0),
('B','E',1/3.0),
('B','C',1/3.0),
('B','D',1/3.0),
('C','D',1/3.0)]
Panswer=nx.Graph()
Panswer.add_weighted_edges_from(edges)
P=bipartite.weighted_projected_graph(self.N, 'ABCDE', ratio=True)
assert_edges_equal(list(P.edges()),Panswer.edges())
for u,v in list(P.edges()):
assert_equal(P[u][v]['weight'],Panswer[u][v]['weight'])
示例4: test_project_weighted_shared
def test_project_weighted_shared(self):
edges = [("A", "B", 2), ("A", "C", 1), ("B", "C", 1), ("B", "D", 1), ("B", "E", 2), ("E", "F", 1)]
Panswer = nx.Graph()
Panswer.add_weighted_edges_from(edges)
P = bipartite.weighted_projected_graph(self.G, "ABCDEF")
assert_edges_equal(P.edges(), Panswer.edges())
for u, v in P.edges():
assert_equal(P[u][v]["weight"], Panswer[u][v]["weight"])
edges = [
("A", "B", 3),
("A", "E", 1),
("A", "C", 1),
("A", "D", 1),
("B", "E", 1),
("B", "C", 1),
("B", "D", 1),
("C", "D", 1),
]
Panswer = nx.Graph()
Panswer.add_weighted_edges_from(edges)
P = bipartite.weighted_projected_graph(self.N, "ABCDE")
assert_edges_equal(P.edges(), Panswer.edges())
for u, v in P.edges():
assert_equal(P[u][v]["weight"], Panswer[u][v]["weight"])
示例5: test_project_weighted_newman
def test_project_weighted_newman(self):
edges = [("A", "B", 1.5), ("A", "C", 0.5), ("B", "C", 0.5), ("B", "D", 1), ("B", "E", 2), ("E", "F", 1)]
Panswer = nx.Graph()
Panswer.add_weighted_edges_from(edges)
P = bipartite.collaboration_weighted_projected_graph(self.G, "ABCDEF")
assert_edges_equal(P.edges(), Panswer.edges())
for u, v in P.edges():
assert_equal(P[u][v]["weight"], Panswer[u][v]["weight"])
edges = [
("A", "B", 11 / 6.0),
("A", "E", 1 / 2.0),
("A", "C", 1 / 3.0),
("A", "D", 1 / 3.0),
("B", "E", 1 / 2.0),
("B", "C", 1 / 3.0),
("B", "D", 1 / 3.0),
("C", "D", 1 / 3.0),
]
Panswer = nx.Graph()
Panswer.add_weighted_edges_from(edges)
P = bipartite.collaboration_weighted_projected_graph(self.N, "ABCDE")
assert_edges_equal(P.edges(), Panswer.edges())
for u, v in P.edges():
assert_equal(P[u][v]["weight"], Panswer[u][v]["weight"])
示例6: test_graph
def test_graph(self):
g = nx.cycle_graph(10)
G = nx.Graph()
G.add_nodes_from(g)
G.add_weighted_edges_from((u, v, u) for u, v in g.edges())
# Dict of dicts
dod = to_dict_of_dicts(G)
GG = from_dict_of_dicts(dod, create_using=nx.Graph())
assert_nodes_equal(sorted(G.nodes()), sorted(GG.nodes()))
assert_edges_equal(sorted(G.edges()), sorted(GG.edges()))
GW = to_networkx_graph(dod, create_using=nx.Graph())
assert_nodes_equal(sorted(G.nodes()), sorted(GW.nodes()))
assert_edges_equal(sorted(G.edges()), sorted(GW.edges()))
GI = nx.Graph(dod)
assert_equal(sorted(G.nodes()), sorted(GI.nodes()))
assert_equal(sorted(G.edges()), sorted(GI.edges()))
# Dict of lists
dol = to_dict_of_lists(G)
GG = from_dict_of_lists(dol, create_using=nx.Graph())
# dict of lists throws away edge data so set it to none
enone = [(u, v, {}) for (u, v, d) in G.edges(data=True)]
assert_nodes_equal(sorted(G.nodes()), sorted(GG.nodes()))
assert_edges_equal(enone, sorted(GG.edges(data=True)))
GW = to_networkx_graph(dol, create_using=nx.Graph())
assert_nodes_equal(sorted(G.nodes()), sorted(GW.nodes()))
assert_edges_equal(enone, sorted(GW.edges(data=True)))
GI = nx.Graph(dol)
assert_nodes_equal(sorted(G.nodes()), sorted(GI.nodes()))
assert_edges_equal(enone, sorted(GI.edges(data=True)))
示例7: test_project_weighted_jaccard
def test_project_weighted_jaccard(self):
edges=[('A','B',2/5.0),
('A','C',1/2.0),
('B','C',1/5.0),
('B','D',1/5.0),
('B','E',2/6.0),
('E','F',1/3.0)]
Panswer=nx.Graph()
Panswer.add_weighted_edges_from(edges)
P=bipartite.overlap_weighted_projected_graph(self.G,'ABCDEF')
assert_edges_equal(list(P.edges()),Panswer.edges())
for u,v in list(P.edges()):
assert_equal(P[u][v]['weight'],Panswer[u][v]['weight'])
edges=[('A','B',3/3.0),
('A','E',1/3.0),
('A','C',1/3.0),
('A','D',1/3.0),
('B','E',1/3.0),
('B','C',1/3.0),
('B','D',1/3.0),
('C','D',1/1.0)]
Panswer=nx.Graph()
Panswer.add_weighted_edges_from(edges)
P=bipartite.overlap_weighted_projected_graph(self.N,'ABCDE')
assert_edges_equal(list(P.edges()),Panswer.edges())
for u,v in P.edges():
assert_equal(P[u][v]['weight'],Panswer[u][v]['weight'])
示例8: test_lollipop_graph
def test_lollipop_graph(self):
# number of nodes = m1 + m2
# number of edges = number_of_edges(complete_graph(m1)) + m2
for m1, m2 in [(3, 5), (4, 10), (3, 20)]:
b=lollipop_graph(m1,m2)
assert_equal(number_of_nodes(b), m1+m2)
assert_equal(number_of_edges(b), m1*(m1-1)/2 + m2)
# Raise NetworkXError if m<2
assert_raises(networkx.exception.NetworkXError,
lollipop_graph, 1, 20)
# Raise NetworkXError if n<0
assert_raises(networkx.exception.NetworkXError,
lollipop_graph, 5, -2)
# lollipop_graph(2,m) = path_graph(m+2)
for m1, m2 in [(2, 5), (2, 10), (2, 20)]:
b=lollipop_graph(m1,m2)
assert_true(is_isomorphic(b, path_graph(m2+2)))
assert_raises(networkx.exception.NetworkXError,
lollipop_graph, m1, m2, create_using=DiGraph())
mb=lollipop_graph(m1, m2, create_using=MultiGraph())
assert_edges_equal(mb.edges(), b.edges())
g=lollipop_graph([1,2,3,4], "abc")
assert_equal(len(g), 7)
assert_equal(g.size(), 9)
示例9: test_trivial6
def test_trivial6(self):
"""Small graph with arbitrary weight attribute"""
G = nx.Graph()
G.add_edge('one', 'two', weight=10, abcd=11)
G.add_edge('two', 'three', weight=11, abcd=10)
assert_edges_equal(nx.max_weight_matching(G, weight='abcd'),
matching_dict_to_set({'one': 'two', 'two': 'one'}))
示例10: test_project_weighted_newman
def test_project_weighted_newman(self):
edges=[('A','B',1.5),
('A','C',0.5),
('B','C',0.5),
('B','D',1),
('B','E',2),
('E','F',1)]
Panswer=nx.Graph()
Panswer.add_weighted_edges_from(edges)
P=bipartite.collaboration_weighted_projected_graph(self.G,'ABCDEF')
assert_edges_equal(list(P.edges()),Panswer.edges())
for u,v in list(P.edges()):
assert_equal(P[u][v]['weight'],Panswer[u][v]['weight'])
edges=[('A','B',11/6.0),
('A','E',1/2.0),
('A','C',1/3.0),
('A','D',1/3.0),
('B','E',1/2.0),
('B','C',1/3.0),
('B','D',1/3.0),
('C','D',1/3.0)]
Panswer=nx.Graph()
Panswer.add_weighted_edges_from(edges)
P=bipartite.collaboration_weighted_projected_graph(self.N,'ABCDE')
assert_edges_equal(list(P.edges()),Panswer.edges())
for u,v in list(P.edges()):
assert_equal(P[u][v]['weight'],Panswer[u][v]['weight'])
示例11: test_trivial4
def test_trivial4(self):
"""Small graph"""
G = nx.Graph()
G.add_edge('one', 'two', weight=10)
G.add_edge('two', 'three', weight=11)
assert_edges_equal(nx.max_weight_matching(G),
matching_dict_to_set({'three': 'two', 'two': 'three'}))
示例12: test_path_graph
def test_path_graph(self):
p=path_graph(0)
assert_true(is_isomorphic(p, null_graph()))
p=path_graph(1)
assert_true(is_isomorphic( p, empty_graph(1)))
p=path_graph(10)
assert_true(is_connected(p))
assert_equal(sorted(d for n, d in p.degree()),
[1, 1, 2, 2, 2, 2, 2, 2, 2, 2])
assert_equal(p.order()-1, p.size())
dp=path_graph(3, create_using=DiGraph())
assert_true(dp.has_edge(0,1))
assert_false(dp.has_edge(1,0))
mp=path_graph(10, create_using=MultiGraph())
assert_edges_equal(mp.edges(), p.edges())
G=path_graph("abc")
assert_equal(len(G), 3)
assert_equal(G.size(), 2)
g=path_graph("abc", nx.DiGraph())
assert_equal(len(g), 3)
assert_equal(g.size(), 2)
assert_true(g.is_directed())
示例13: test_decoding2
def test_decoding2(self):
# Example from "An Optimal Algorithm for Prufer Codes".
sequence = [2, 4, 0, 1, 3, 3]
tree = nx.from_prufer_sequence(sequence)
assert_nodes_equal(list(tree), list(range(8)))
edges = [(0, 1), (0, 4), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
assert_edges_equal(list(tree.edges()), edges)
示例14: test_s_blossom_relabel_expand
def test_s_blossom_relabel_expand(self):
"""Create S-blossom, relabel as T, expand:"""
G = nx.Graph()
G.add_weighted_edges_from([(1, 2, 23), (1, 5, 22), (1, 6, 15),
(2, 3, 25), (3, 4, 22), (4, 5, 25),
(4, 8, 14), (5, 7, 13)])
assert_edges_equal(nx.max_weight_matching(G),
matching_dict_to_set({1: 6, 2: 3, 3: 2, 4: 8, 5: 7, 6: 1, 7: 5, 8: 4}))
示例15: test_nested_s_blossom_relabel_expand
def test_nested_s_blossom_relabel_expand(self):
"""Create nested S-blossom, relabel as T, expand:"""
G = nx.Graph()
G.add_weighted_edges_from([(1, 2, 19), (1, 3, 20), (1, 8, 8),
(2, 3, 25), (2, 4, 18), (3, 5, 18),
(4, 5, 13), (4, 7, 7), (5, 6, 7)])
assert_edges_equal(nx.max_weight_matching(G),
matching_dict_to_set({1: 8, 2: 3, 3: 2, 4: 7, 5: 6, 6: 5, 7: 4, 8: 1}))