summaryrefslogtreecommitdiff
path: root/networkx/algorithms/community/tests
diff options
context:
space:
mode:
authorAric Hagberg <aric.hagberg+github@gmail.com>2017-01-15 16:50:27 -0700
committerGitHub <noreply@github.com>2017-01-15 16:50:27 -0700
commit8f1bcdf8cdee38517ba64754bf2e3f693f6aaa7e (patch)
tree8a6b9061a9880636d83fd3961542a306843bf618 /networkx/algorithms/community/tests
parent23d7b443d5eac73e47a20816f484b493d8ef8440 (diff)
parentcbdf7b125c5dc1b1ef367c8cd72877d3f6910cc5 (diff)
downloadnetworkx-8f1bcdf8cdee38517ba64754bf2e3f693f6aaa7e.tar.gz
Merge pull request #1729 from jfinkels/modularity
Adds modularity measure for communities.
Diffstat (limited to 'networkx/algorithms/community/tests')
-rw-r--r--networkx/algorithms/community/tests/test_quality.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/networkx/algorithms/community/tests/test_quality.py b/networkx/algorithms/community/tests/test_quality.py
index b8ee94a3..920e2dec 100644
--- a/networkx/algorithms/community/tests/test_quality.py
+++ b/networkx/algorithms/community/tests/test_quality.py
@@ -14,9 +14,11 @@ from __future__ import division
from nose.tools import assert_almost_equal
-from networkx.generators.classic import barbell_graph
-from networkx.algorithms.community.quality import coverage
-from networkx.algorithms.community.quality import performance
+import networkx as nx
+from networkx import barbell_graph
+from networkx import coverage
+from networkx import performance
+
class TestPerformance(object):
"""Unit tests for the :func:`performance` function."""
@@ -50,3 +52,11 @@ class TestCoverage(object):
G = barbell_graph(3, 0)
partition = [{0, 1, 2}, {3, 4, 5}]
assert_almost_equal(6 / 7, coverage(G, partition))
+
+
+def test_modularity():
+ G = nx.barbell_graph(3, 0)
+ C = [{0, 1, 4}, {2, 3, 5}]
+ assert_almost_equal(-16 / (14 ** 2), nx.modularity(G, C))
+ C = [{0, 1, 2}, {3, 4, 5}]
+ assert_almost_equal((35 * 2) / (14 ** 2), nx.modularity(G, C))