HEX
Server: Apache
System: Linux vps-cdc32557.vps.ovh.ca 5.15.0-156-generic #166-Ubuntu SMP Sat Aug 9 00:02:46 UTC 2025 x86_64
User: hanode (1017)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //lib/python3/dist-packages/networkx/generators/tests/test_ego.py
#!/usr/bin/env python
"""
ego graph
---------
"""

import networkx as nx
from networkx.testing.utils import *


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])