From a2fe2361a4ee3742540fcf48abc6b3a198d76bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Mon, 18 Jul 2005 12:58:37 +0000 Subject: [PATCH] * assert'u yapistir --- pisi/graph.py | 2 ++ tests/graphtests.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pisi/graph.py b/pisi/graph.py index eae17909..e0befeaf 100644 --- a/pisi/graph.py +++ b/pisi/graph.py @@ -88,5 +88,7 @@ class digraph(object): def topological_sort(self): l = [] self.dfs(lambda u: l.append(u)) + l.reverse() return l + diff --git a/tests/graphtests.py b/tests/graphtests.py index f1a21aa0..469e5b3d 100644 --- a/tests/graphtests.py +++ b/tests/graphtests.py @@ -11,10 +11,15 @@ class GraphTestCase(unittest.TestCase): g0.from_list([ (1,2), (1,3), (2,3), (3,4), (4, 5), (4,1)]) g1 = graph.digraph() - g1.from_list([ (0,2), (0,3), (3,4), (2,4), (5,4) ]) + g1.from_list([ (0,2), (0,3), (3,4), (2,4), (0,5), (5,4) ]) self.g1 = g1 - + + def testCycle(self): + pass + def testTopologicalSort(self): - print self.g1.topological_sort() + order = self.g1.topological_sort() + self.assertEqual(order[0], 0) + self.assertEqual(order[len(order)-1], 4) suite = unittest.makeSuite(GraphTestCase)