Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / algorithms / community / tests / test_modularity_max.py @ 5cef0f13

History | View | Annotate | Download (1.34 KB)

1
from itertools import combinations
2

    
3
from nose.tools import assert_equal
4
from nose.tools import raises
5

    
6
import networkx as nx
7
from networkx.algorithms.community import (
8
    greedy_modularity_communities,
9
    _naive_greedy_modularity_communities)
10

    
11

    
12
class TestCNM(object):
13

    
14
    def setup(self):
15
        self.G = nx.karate_club_graph()
16

    
17
    def _check_communities(self, expected):
18
        communities = set(greedy_modularity_communities(self.G))
19
        assert_equal(communities, expected)
20

    
21
    def test_karate_club(self):
22
        john_a = frozenset([
23
            8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33])
24
        mr_hi = frozenset([0, 4, 5, 6, 10, 11, 16, 19])
25
        overlap = frozenset([1, 2, 3, 7, 9, 12, 13, 17, 21])
26
        self._check_communities({john_a, overlap, mr_hi})
27

    
28

    
29
class TestNaive(object):
30

    
31
    def setup(self):
32
        self.G = nx.karate_club_graph()
33

    
34
    def _check_communities(self, expected):
35
        communities = set(_naive_greedy_modularity_communities(self.G))
36
        assert_equal(communities, expected)
37

    
38
    def test_karate_club(self):
39
        john_a = frozenset([
40
            8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33])
41
        mr_hi = frozenset([0, 4, 5, 6, 10, 11, 16, 19])
42
        overlap = frozenset([1, 2, 3, 7, 9, 12, 13, 17, 21])
43
        self._check_communities({john_a,  overlap, mr_hi})