# Path: pyalgs/algorithms/graphs/topological_sort.py
# class DepthFirstOrder(object):
# 
#     marked = None
#     reversePostOrder = None
# 
#     def __init__(self, G):
#         if isinstance(G, DirectedEdgeWeightedGraph):
#             G = G.to_digraph()
# 
#         self.reversePostOrder = Stack.create()
#         vertex_count = G.vertex_count()
#         self.marked = [False] * vertex_count
# 
#         for v in range(vertex_count):
#             if not self.marked[v]:
#                 self.dfs(G, v)
# 
#     def dfs(self, G, v):
#         self.marked[v] = True
#         for w in G.adj(v):
#             if not self.marked[w]:
#                 self.dfs(G, w)
#         self.reversePostOrder.push(v)
# 
#     def postOrder(self):
#         return self.reversePostOrder.iterate()
# 
# Path: tests/algorithms/graphs/util.py
# def create_dag():
#     dag = Digraph(7)
# 
#     dag.add_edge(0, 5)
#     dag.add_edge(0, 2)
#     dag.add_edge(0, 1)
#     dag.add_edge(3, 6)
#     dag.add_edge(3, 5)
#     dag.add_edge(3, 4)
#     dag.add_edge(5, 4)
#     dag.add_edge(6, 4)
#     dag.add_edge(6, 0)
#     dag.add_edge(3, 2)
#     dag.add_edge(1, 4)
# 
#     return dag


import unittest
from pyalgs.algorithms.graphs.topological_sort import DepthFirstOrder
from tests.algorithms.graphs.util import create_dag



class DepthFirstOrderUnitTest(unittest.TestCase):

    def test_topological_sort(self):
        G = create_dag()

        topological_sort = DepthFirstOrder(G)


# Path: pyalgs/algorithms/graphs/topological_sort.py
# class DepthFirstOrder(object):
# 
#     marked = None
#     reversePostOrder = None
# 
#     def __init__(self, G):
#         if isinstance(G, DirectedEdgeWeightedGraph):
#             G = G.to_digraph()
# 
#         self.reversePostOrder = Stack.create()
#         vertex_count = G.vertex_count()
#         self.marked = [False] * vertex_count
# 
#         for v in range(vertex_count):
#             if not self.marked[v]:
#                 self.dfs(G, v)
# 
#     def dfs(self, G, v):
#         self.marked[v] = True
#         for w in G.adj(v):
#             if not self.marked[w]:
#                 self.dfs(G, w)
#         self.reversePostOrder.push(v)
# 
#     def postOrder(self):
#         return self.reversePostOrder.iterate()
# 
# Path: tests/algorithms/graphs/util.py
# def create_dag():
#     dag = Digraph(7)
# 
#     dag.add_edge(0, 5)
#     dag.add_edge(0, 2)
#     dag.add_edge(0, 1)
#     dag.add_edge(3, 6)
#     dag.add_edge(3, 5)
#     dag.add_edge(3, 4)
#     dag.add_edge(5, 4)
#     dag.add_edge(6, 4)
#     dag.add_edge(6, 0)
#     dag.add_edge(3, 2)
#     dag.add_edge(1, 4)
# 
#     return dag


# Path: tests/algorithms/graphs/topological_sort_unit_test.py
import unittest
from pyalgs.algorithms.graphs.topological_sort import DepthFirstOrder
from tests.algorithms.graphs.util import create_dag




class DepthFirstOrderUnitTest(unittest.TestCase):

    def test_topological_sort(self):
        G = create_dag()

        topological_sort = DepthFirstOrder(G)


        print(' => '.join([str(i) for i in topological_sort.postOrder()]))