diff options
author | Yann Lanthony <yann.lanthony@gmail.com> | 2018-01-08 15:08:55 +0300 |
---|---|---|
committer | Yann Lanthony <yann.lanthony@gmail.com> | 2018-01-08 15:08:55 +0300 |
commit | 516f909db4cd1ad7dd175273849bac8fc9897066 (patch) | |
tree | 64466ca14abe777139d6cbdc0b0a27f7dcc65eb2 /tests | |
parent | 924dbc8d32105d650da13fc5b940c3cd60014649 (diff) |
[graph] add nodesFromNode method based on reverse dfs visit
Get the whole node chain from a start node to the graph leaves following graph edges
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_graph.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_graph.py b/tests/test_graph.py index f08cfc82..caa5bd81 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -158,3 +158,31 @@ def test_transitive_reduction(): for node, (minDepth, maxDepth) in depthPerNode.iteritems(): assert node.depth == maxDepth + +def test_graph_reverse_dfs(): + graph = Graph('Test reverse DFS') + + # ------------\ + # / ~ C - E - F + # A - B + # ~ D + + A = graph.addNewNode('Ls', input='/tmp') + B = graph.addNewNode('AppendText', inputText=A.output) + C = graph.addNewNode('AppendText', inputText=B.output) + D = graph.addNewNode('AppendText', inputText=B.output) + E = graph.addNewNode('Ls', input=C.output) + F = graph.addNewNode('AppendText', input=A.output, inputText=E.output) + + # Get all nodes from A (use set, order not guaranteed) + nodes = graph.nodesFromNode(A)[0] + assert set(nodes) == {A, B, D, C, E, F} + # Get all nodes from B + nodes = graph.nodesFromNode(B)[0] + assert set(nodes) == {B, D, C, E, F} + # Get all nodes of type AppendText from B + nodes = graph.nodesFromNode(B, filterType='AppendText')[0] + assert set(nodes) == {B, D, C, F} + # Get all nodes from C (order guaranteed) + nodes = graph.nodesFromNode(C)[0] + assert nodes == [C, E, F] |