Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / generators / tests / test_ego.py @ 5cef0f13

History | View | Annotate | Download (1.35 KB)

1
#!/usr/bin/env python
2
"""
3
ego graph
4
---------
5
"""
6

    
7
from nose.tools import assert_true
8
import networkx as nx
9
from networkx.testing.utils import *
10

    
11

    
12
class TestGeneratorEgo():
13
    def test_ego(self):
14
        G = nx.star_graph(3)
15
        H = nx.ego_graph(G, 0)
16
        assert_true(nx.is_isomorphic(G, H))
17
        G.add_edge(1, 11)
18
        G.add_edge(2, 22)
19
        G.add_edge(3, 33)
20
        H = nx.ego_graph(G, 0)
21
        assert_true(nx.is_isomorphic(nx.star_graph(3), H))
22
        G = nx.path_graph(3)
23
        H = nx.ego_graph(G, 0)
24
        assert_edges_equal(H.edges(), [(0, 1)])
25
        H = nx.ego_graph(G, 0, undirected=True)
26
        assert_edges_equal(H.edges(), [(0, 1)])
27
        H = nx.ego_graph(G, 0, center=False)
28
        assert_edges_equal(H.edges(), [])
29

    
30
    def test_ego_distance(self):
31
        G = nx.Graph()
32
        G.add_edge(0, 1, weight=2, distance=1)
33
        G.add_edge(1, 2, weight=2, distance=2)
34
        G.add_edge(2, 3, weight=2, distance=1)
35
        assert_nodes_equal(nx.ego_graph(G, 0, radius=3).nodes(), [0, 1, 2, 3])
36
        eg = nx.ego_graph(G, 0, radius=3, distance='weight')
37
        assert_nodes_equal(eg.nodes(), [0, 1])
38
        eg = nx.ego_graph(G, 0, radius=3, distance='weight', undirected=True)
39
        assert_nodes_equal(eg.nodes(), [0, 1])
40
        eg = nx.ego_graph(G, 0, radius=3, distance='distance')
41
        assert_nodes_equal(eg.nodes(), [0, 1, 2])