diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.9/site-packages/networkx/generators/tests/test_ego.py	Mon Mar 22 18:12:50 2021 +0000
@@ -0,0 +1,39 @@
+"""
+ego graph
+---------
+"""
+
+import networkx as nx
+from networkx.testing.utils import assert_edges_equal, assert_nodes_equal
+
+
+class TestGeneratorEgo:
+    def test_ego(self):
+        G = nx.star_graph(3)
+        H = nx.ego_graph(G, 0)
+        assert nx.is_isomorphic(G, H)
+        G.add_edge(1, 11)
+        G.add_edge(2, 22)
+        G.add_edge(3, 33)
+        H = nx.ego_graph(G, 0)
+        assert nx.is_isomorphic(nx.star_graph(3), H)
+        G = nx.path_graph(3)
+        H = nx.ego_graph(G, 0)
+        assert_edges_equal(H.edges(), [(0, 1)])
+        H = nx.ego_graph(G, 0, undirected=True)
+        assert_edges_equal(H.edges(), [(0, 1)])
+        H = nx.ego_graph(G, 0, center=False)
+        assert_edges_equal(H.edges(), [])
+
+    def test_ego_distance(self):
+        G = nx.Graph()
+        G.add_edge(0, 1, weight=2, distance=1)
+        G.add_edge(1, 2, weight=2, distance=2)
+        G.add_edge(2, 3, weight=2, distance=1)
+        assert_nodes_equal(nx.ego_graph(G, 0, radius=3).nodes(), [0, 1, 2, 3])
+        eg = nx.ego_graph(G, 0, radius=3, distance="weight")
+        assert_nodes_equal(eg.nodes(), [0, 1])
+        eg = nx.ego_graph(G, 0, radius=3, distance="weight", undirected=True)
+        assert_nodes_equal(eg.nodes(), [0, 1])
+        eg = nx.ego_graph(G, 0, radius=3, distance="distance")
+        assert_nodes_equal(eg.nodes(), [0, 1, 2])