Package logilab :: Package common :: Package test :: Module unittest_graph
[frames] | no frames]

Source Code for Module logilab.common.test.unittest_graph

 1  # unit tests for the cache module 
 2   
 3  from logilab.common.testlib import TestCase, unittest_main 
 4  from logilab.common.graph import get_cycles, has_path 
 5   
6 -class getCyclesTC(TestCase):
7
8 - def test_known0(self):
9 self.assertEqual(get_cycles({1:[2], 2:[3], 3:[1]}), [[1, 2, 3]])
10
11 - def test_known1(self):
12 self.assertEqual(get_cycles({1:[2], 2:[3], 3:[1, 4], 4:[3]}), [[1, 2, 3], [3, 4]])
13
14 - def test_known2(self):
15 self.assertEqual(get_cycles({1:[2], 2:[3], 3:[0], 0:[]}), [])
16 17
18 -class hasPathTC(TestCase):
19
20 - def test_direct_connection(self):
21 self.assertEquals(has_path({'A': ['B'], 'B': ['A']}, 'A', 'B'), ['B'])
22
24 self.assertEquals(has_path({'A': ['B'], 'B': ['A', 'C'], 'C': ['B']}, 'A', 'C'), ['B', 'C'])
25
26 - def test_no_connection(self):
27 self.assertEquals(has_path({'A': ['B'], 'B': ['A']}, 'A', 'C'), None)
28
29 - def test_cycle(self):
30 self.assertEquals(has_path({'A': ['A']}, 'A', 'B'), None)
31 32 if __name__ == "__main__": 33 unittest_main() 34