aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/networkx/algorithms/centrality/tests/test_voterank.py
blob: a5cfb6107a64f1c1e0923297a81c7df7172d5afe (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Unit tests for VoteRank.
"""

import networkx as nx


class TestVoteRankCentrality:
    # Example Graph present in reference paper
    def test_voterank_centrality_1(self):
        G = nx.Graph()
        G.add_edges_from(
            [
                (7, 8),
                (7, 5),
                (7, 9),
                (5, 0),
                (0, 1),
                (0, 2),
                (0, 3),
                (0, 4),
                (1, 6),
                (2, 6),
                (3, 6),
                (4, 6),
            ]
        )
        assert [0, 7, 6] == nx.voterank(G)

    def test_voterank_emptygraph(self):
        G = nx.Graph()
        assert [] == nx.voterank(G)

    # Graph unit test
    def test_voterank_centrality_2(self):
        G = nx.florentine_families_graph()
        d = nx.voterank(G, 4)
        exact = ["Medici", "Strozzi", "Guadagni", "Castellani"]
        assert exact == d

    # DiGraph unit test
    def test_voterank_centrality_3(self):
        G = nx.gnc_graph(10, seed=7)
        d = nx.voterank(G, 4)
        exact = [3, 6, 8]
        assert exact == d

    # MultiGraph unit test
    def test_voterank_centrality_4(self):
        G = nx.MultiGraph()
        G.add_edges_from(
            [(0, 1), (0, 1), (1, 2), (2, 5), (2, 5), (5, 6), (5, 6), (2, 4), (4, 3)]
        )
        exact = [2, 1, 5, 4]
        assert exact == nx.voterank(G)

    # MultiDiGraph unit test
    def test_voterank_centrality_5(self):
        G = nx.MultiDiGraph()
        G.add_edges_from(
            [(0, 1), (0, 1), (1, 2), (2, 5), (2, 5), (5, 6), (5, 6), (2, 4), (4, 3)]
        )
        exact = [2, 0, 5, 4]
        assert exact == nx.voterank(G)