forked from lordgrilo/Holes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
40 lines (31 loc) · 1.37 KB
/
tests.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
import unittest
import __init__ as nxigraph
class TestNameAttributes(unittest.TestCase):
"""
Tests attribute name compatibility between igraph and networkx.
.. note:: I am assuming the convention of using "name" to refer to the
name of vertices following the tutorial_.
.. _tutorial: http://www.cs.rhul.ac.uk/home/tamas/development/igraph/tutorial/tutorial.html#setting-and-retrieving-attributes
"""
def setUp(self):
edgelist = [('blue', 'purple'), # Our sample network of strings
('blue', 'green'),
('blue', 'red'),
('yellow', 'green'),
('green', 'orange')]
self.nxg = nxigraph.NXiGraph() # Sample object
self.nxg.add_edges_from(edgelist) # Use standard networkx api
def testNames(self):
"Simple name test"
self.assertEqual(self.nxg.nodes(), self.nxg.igraph.vs["name"])
def testNamesAndDegree(self):
"""
Tests names more stringently using degree.
.. note:: Ambiguous names outside the scope of this test.
"""
for n in self.nxg.nodes():
node_name = str(n)
igraph_node = self.nxg.igraph.vs.select(name_eq=node_name)
self.assertEqual(self.nxg.degree(n), igraph_node.degree()[0])
if __name__ == '__main__':
unittest.main()