[pypy-svn] r18089 - in pypy/dist/pypy/tool/algo: . test

arigo at codespeak.net arigo at codespeak.net
Sun Oct 2 20:05:55 CEST 2005


Author: arigo
Date: Sun Oct  2 20:05:49 2005
New Revision: 18089

Modified:
   pypy/dist/pypy/tool/algo/graphlib.py
   pypy/dist/pypy/tool/algo/test/test_graphlib.py
Log:
Oups, bug and test.


Modified: pypy/dist/pypy/tool/algo/graphlib.py
==============================================================================
--- pypy/dist/pypy/tool/algo/graphlib.py	(original)
+++ pypy/dist/pypy/tool/algo/graphlib.py	Sun Oct  2 20:05:49 2005
@@ -95,7 +95,7 @@
             #print '-->', ''.join(component)
             edge_weights = {}
             random_vertex = component.iterkeys().next()
-            for cycle in all_cycles(random_vertex, vertices, edges):
+            for cycle in all_cycles(random_vertex, component, edges):
                 #print '\tcycle:', [e.source+e.target for e in cycle]
                 for edge in cycle:
                     edge_weights[edge] = edge_weights.get(edge, 0) + 1

Modified: pypy/dist/pypy/tool/algo/test/test_graphlib.py
==============================================================================
--- pypy/dist/pypy/tool/algo/test/test_graphlib.py	(original)
+++ pypy/dist/pypy/tool/algo/test/test_graphlib.py	Sun Oct  2 20:05:49 2005
@@ -50,3 +50,23 @@
     assert (edges['A'][0] in result or
             edges['B'][1] in result or
             edges['E'][0] in result)
+
+def test_break_cycles_2():
+    # a graph with 20 loops of length 10 each, plus an edge from each loop to
+    # the next
+    edges = {}
+    for i in range(200):
+        j = i+1
+        if j % 10 == 0:
+            j -= 10
+        edges[i] = [Edge(i, j)]
+    for i in range(20):
+        edges[i*10].append(Edge(i*10, (i*10+15) % 200))
+    #
+    result = list(break_cycles(edges, edges))
+    assert len(result) == 20
+    result = [(edge.source, edge.target) for edge in result]
+    result.sort()
+    for i in range(20):
+        assert i*10 <= result[i][0] <= (i+1)*10
+        assert i*10 <= result[i][1] <= (i+1)*10



More information about the Pypy-commit mailing list