summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>2011-01-31 18:37:27 +0100
committerNicolas Chauvat <nicolas.chauvat@logilab.fr>2011-01-31 18:37:27 +0100
commit9e33dcf029feb83c86aabf5b278e80e876fb2d3c (patch)
tree673ed2ff2ff473188badd60fc7be18abf6e10f1e /test
parent59e46b0d804514c026479abe7b1562cfd70d16ca (diff)
downloadlogilab-common-9e33dcf029feb83c86aabf5b278e80e876fb2d3c.tar.gz
graph: fix and test ordered_nodes() [closes #60288]
Diffstat (limited to 'test')
-rw-r--r--test/unittest_graph.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/test/unittest_graph.py b/test/unittest_graph.py
index 06e1046..e72d8d4 100644
--- a/test/unittest_graph.py
+++ b/test/unittest_graph.py
@@ -18,7 +18,7 @@
# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
from logilab.common.testlib import TestCase, unittest_main
-from logilab.common.graph import get_cycles, has_path
+from logilab.common.graph import get_cycles, has_path, ordered_nodes, UnorderableGraph
class getCyclesTC(TestCase):
@@ -46,5 +46,41 @@ class hasPathTC(TestCase):
def test_cycle(self):
self.assertEqual(has_path({'A': ['A']}, 'A', 'B'), None)
+class ordered_nodesTC(TestCase):
+
+ def test_one_item(self):
+ graph = {'a':[]}
+ ordered = ordered_nodes(graph)
+ self.assertEqual(ordered, ('a',))
+
+ def test_single_dependency(self):
+ graph = {'a':[], 'b':['a']}
+ ordered = ordered_nodes(graph)
+ self.assertEqual(ordered, ('a','b'))
+
+ def test_two_items_no_dependency(self):
+ graph = {'a':[], 'b':[]}
+ ordered = ordered_nodes(graph)
+ self.assertEqual(ordered, ('a','b'))
+
+ def test_three_items_no_dependency(self):
+ graph = {'a':[], 'b':[], 'c':[]}
+ ordered = ordered_nodes(graph)
+ self.assertEqual(ordered, ('a', 'b', 'c'))
+
+ def test_three_items_one_dependency(self):
+ graph = {'a': ['b'], 'b': [], 'c':[]}
+ ordered = ordered_nodes(graph)
+ self.assertEqual(ordered, ('b', 'c', 'a'))
+
+ def test_three_items_two_dependencies(self):
+ graph = {'a': ['b'], 'b': ['c'], 'c':[]}
+ ordered = ordered_nodes(graph)
+ self.assertEqual(ordered, ('c', 'b', 'a'))
+
+ def test_bad_graph(self):
+ graph = {'a':['b']}
+ self.assertRaises(UnorderableGraph, ordered_nodes, graph)
+
if __name__ == "__main__":
unittest_main()