~ubuntu-branches/ubuntu/trusty/python-networkx/trusty

« back to all changes in this revision

Viewing changes to networkx/algorithms/centrality/tests/test_current_flow_closeness.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-12-10 23:50:27 UTC
  • mfrom: (1.2.4 upstream) (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20101210235027-b2supdwo0ad39d3s
Tags: 1.3-1
* New upstream release
* debian/patches/changeset_r1745.diff
  - dropped, available in upstream release
* debian/patches/10_doc_relocation
  - refreshed patch for new upstream code
* debian/control
  - upstream code is now compatible with 2.6 or later only
  - bump Standards-Version to 3.9.1 (no changes needed)
* debian/{control, rules}
  - run unittests at build time, b-d on python-nose added
* debian/copyright
  - removed reference to /usr/share/common-licenses/BSD
* Create a -doc package ; thanks to Yaroslav Halchenko for the report;
  Closes: #567369
  - (d/control) define a new binary package, and add depends on sphinx (>= 1)
  - (d/rules) build documentation, install it into the new -doc package
  - (d/patches/30_use_local_objects.inv) use local copy of remote objects.inv
* debian/{control, rules}
  - moved to dh7 and "reduced" rules file
* debian/rules
  - refer to built code when building doc
* debian/python-networkx-doc.doc-base
  - added doc-base information
* debian/patches/40_add_networkxcss
  - added as patch, since networkx.css is missing from the tarball, but needed
    to display properly HTML documentation
* debian/patches/50_boundary-test-fix.patch
  - upstream patch to restrict node boundary test cases to valid range
* debian/patches/60_remove_svn_refs.diff
  - upstream patch to remove references to old SVN repository (now Mercurial)
* debian/patches/70_set_matplotlib_ps_backend.patch
  - set matplotlib backend to 'PS', so a DISPLAY it's not required and the
    tests can be run in a "reduced" environment

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
from nose.tools import *
 
3
from nose import SkipTest
 
4
import networkx
 
5
 
 
6
class TestFlowClosenessCentrality(object):
 
7
    @classmethod
 
8
    def setupClass(cls):
 
9
        global np
 
10
        try:
 
11
            import numpy as np
 
12
        except ImportError:
 
13
            raise SkipTest('NumPy not available.')
 
14
        
 
15
        
 
16
    def test_K4(self):
 
17
        """Closeness centrality: K4"""
 
18
        G=networkx.complete_graph(4)
 
19
        b=networkx.current_flow_closeness_centrality(G,normalized=True)
 
20
        b_answer={0: 2.0, 1: 2.0, 2: 2.0, 3: 2.0}
 
21
        for n in sorted(G):
 
22
            assert_almost_equal(b[n],b_answer[n])
 
23
 
 
24
 
 
25
    def test_P4_normalized(self):
 
26
        """Closeness centrality: P4 normalized"""
 
27
        G=networkx.path_graph(4)
 
28
        b=networkx.current_flow_closeness_centrality(G,normalized=True)
 
29
        b_answer={0: 1./2, 1: 3./4, 2: 3./4, 3:1./2}
 
30
        for n in sorted(G):
 
31
            assert_almost_equal(b[n],b_answer[n])
 
32
 
 
33
 
 
34
    def test_P4(self):
 
35
        """Closeness centrality: P4"""
 
36
        G=networkx.path_graph(4)
 
37
        b=networkx.current_flow_closeness_centrality(G,normalized=False)
 
38
        b_answer={0: 1.0/6, 1: 1.0/4, 2: 1.0/4, 3:1.0/6}
 
39
        for n in sorted(G):
 
40
            assert_almost_equal(b[n],b_answer[n])
 
41
 
 
42
    def test_star(self):
 
43
        """Closeness centrality: star """
 
44
        G=networkx.Graph()
 
45
        G.add_star(['a','b','c','d'])
 
46
        b=networkx.current_flow_closeness_centrality(G,normalized=True)
 
47
        b_answer={'a': 1.0, 'b': 0.6, 'c': 0.6, 'd':0.6}
 
48
        for n in sorted(G):
 
49
            assert_almost_equal(b[n],b_answer[n])
 
50
 
 
51
 
 
52
 
 
53
class TestWeightedFlowClosenessCentrality(object):
 
54
    pass