/
test_hig.py
59 lines (53 loc) · 1.76 KB
/
test_hig.py
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
import unittest
import networkx as nx
from nose.tools import assert_equal, assert_raises, \
assert_true
from .util import json_load
from .test_util import make_path
from hig import construct_hig_from_interactions
from interactions import InteractionsUtil as IU
class HIGTest(unittest.TestCase):
def setUp(self):
self.interactions = IU.clean_interactions(
json_load(
make_path('test/data/enron_test.json')
)
)
def test_construct_hig(self):
hig = construct_hig_from_interactions(
self.interactions
)
a, b, c, d, e, f = ('A', 'B', 'C', 'D', 'E', 'F')
assert_equal(
sorted(
range(1, 7) +
[a, b, c, d, e, f, 'XXX']
),
sorted(hig.nodes()))
print hig.edges()
assert_equal(
sorted(
[(a, 1), (1, b), (1, c), (1, d),
(a, 2), (2, f),
(d, 3), (3, e),
(a, 4), (4, b),
(d, 5), (5, f),
(6, u'XXX'), (u'XXX', 6)
]),
sorted(hig.edges())
)
def test_construct_hig_interacting_ids(self):
self.interactions.append({'sender_id': 1,
'recipient_ids': [1],
'message_id': 7})
assert_raises(ValueError,
construct_hig_from_interactions,
self.interactions)
def test_pagerank_on_hig(self):
pr = nx.pagerank(
construct_hig_from_interactions(self.interactions)
)
assert_true(pr['A'] < pr['F'])
assert_true(pr['A'] < pr['B'])
assert_true(pr['A'] < pr['C'])
assert_true(pr['A'] < pr['D'])