Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/generators/tests/test_ego.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """ | |
2 ego graph | |
3 --------- | |
4 """ | |
5 | |
6 import networkx as nx | |
7 from networkx.testing.utils import assert_edges_equal, assert_nodes_equal | |
8 | |
9 | |
10 class TestGeneratorEgo: | |
11 def test_ego(self): | |
12 G = nx.star_graph(3) | |
13 H = nx.ego_graph(G, 0) | |
14 assert nx.is_isomorphic(G, H) | |
15 G.add_edge(1, 11) | |
16 G.add_edge(2, 22) | |
17 G.add_edge(3, 33) | |
18 H = nx.ego_graph(G, 0) | |
19 assert nx.is_isomorphic(nx.star_graph(3), H) | |
20 G = nx.path_graph(3) | |
21 H = nx.ego_graph(G, 0) | |
22 assert_edges_equal(H.edges(), [(0, 1)]) | |
23 H = nx.ego_graph(G, 0, undirected=True) | |
24 assert_edges_equal(H.edges(), [(0, 1)]) | |
25 H = nx.ego_graph(G, 0, center=False) | |
26 assert_edges_equal(H.edges(), []) | |
27 | |
28 def test_ego_distance(self): | |
29 G = nx.Graph() | |
30 G.add_edge(0, 1, weight=2, distance=1) | |
31 G.add_edge(1, 2, weight=2, distance=2) | |
32 G.add_edge(2, 3, weight=2, distance=1) | |
33 assert_nodes_equal(nx.ego_graph(G, 0, radius=3).nodes(), [0, 1, 2, 3]) | |
34 eg = nx.ego_graph(G, 0, radius=3, distance="weight") | |
35 assert_nodes_equal(eg.nodes(), [0, 1]) | |
36 eg = nx.ego_graph(G, 0, radius=3, distance="weight", undirected=True) | |
37 assert_nodes_equal(eg.nodes(), [0, 1]) | |
38 eg = nx.ego_graph(G, 0, radius=3, distance="distance") | |
39 assert_nodes_equal(eg.nodes(), [0, 1, 2]) |