Package visgraph :: Package unittests :: Module pathtest
[hide private]
[frames] | no frames]

Source Code for Module visgraph.unittests.pathtest

 1  ''' 
 2  A module for path related unit tests. 
 3  ''' 
 4   
 5  import visgraph.pathcore as vg_pcore 
 6  import visgraph.graphcore as vg_gcore 
 7   
8 -def buildPathGraph():
9 g = vg_gcore.Graph() 10 n0 = g.addNode() 11 n1 = g.addNode() 12 n2 = g.addNode() 13 n3 = g.addNode() 14 n4 = g.addNode() 15 16 g.addEdge(n0, n1) 17 g.addEdge(n0, n2) 18 g.addEdge(n1, n3) 19 g.addEdge(n1, n4) 20 21 return g,n0,n4
22
23 -def vgtest_basic_path_search():
24 g,begin_node,end_node = buildPathGraph() 25 res = g.pathSearchFromTo(begin_node, end_node) 26 for eid in res: 27 eid, fromid, toid, einfo = g.getEdge(eid) 28 print '%d --(%d)--> %d' % (fromid, eid, toid)
29
30 -def test_callback_false(graph, edge, depth):
31 print 'DENY EDGE: %s' % repr(edge)
32
33 -def test_callback_true(graph, edge, depth):
34 print 'ALLOW EDGE: %s' % repr(edge) 35 return True
36
37 -def vgtest_path_callback_false_test():
38 g,begin_node,end_node = buildPathGraph() 39 res = g.pathSearchFromTo(begin_node, end_node, edgecb=test_callback_false) 40 if len(res) != 0: 41 raise Exception('Should Not Have Answers!')
42
43 -def vgtest_path_callback_true_test():
44 g,begin_node,end_node = buildPathGraph() 45 res = g.pathSearchFromTo(begin_node, end_node, edgecb=test_callback_true) 46 if len(res) == 0: 47 raise Exception('Should Have Answers!') 48 print repr(res)
49