d2_graph_test.py 1.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
import unittest

from d2_graph import D2Graph
from d_graph import Dgraph

from tests.d_graph_data import unit_d_graph, unit_overlapp_d_graph, complete_graph


class TestD2Graph(unittest.TestCase):
    def test_construction(self):
Yoann Dufresne's avatar
Yoann Dufresne committed
11
        d2 = D2Graph(complete_graph, 6)
12
13
14
15
16
17
18
19

        # Evaluate the number of candidate unit d_graphs generated
        for node, candidates in d2.d_graphs.items():
            if node == "C" or node == "B2":
                self.assertEquals(1, len(candidates))
            else:
                self.assertEquals(0, len(candidates))

Yoann Dufresne's avatar
Yoann Dufresne committed
20
21
        # Evaluate the index
        self.assertEquals(13, len(d2.index))
22

Yoann Dufresne's avatar
Yoann Dufresne committed
23
24
25
26
27
28
29
        overlap_key = ('A1', 'A2', 'B0', 'B1', 'B2', 'C')
        for dmer, dg_lst in d2.index.items():
            if dmer == overlap_key:
                self.assertEquals(2, len(d2.index[dmer]))
                self.assertNotEquals(d2.index[dmer][0], d2.index[dmer][1])
            else:
                self.assertEquals(1, len(d2.index[dmer]))
30
31


32
    def test_to_nx_graph(self):
Yoann Dufresne's avatar
Yoann Dufresne committed
33
        d2 = D2Graph(complete_graph, 6)
34
35
36
37
38
39
40
41
        d2G, node_names = d2.to_nx_graph()
        nodes = list(d2G.nodes())
        self.assertEquals(2, len(nodes))
        edges = list(d2G.edges())
        self.assertEquals(1, len(edges))



42
43
if __name__ == "__main__":
    unittest.main()