[pypy-svn] r73740 - in pypy/branch/blackhole-improvement/pypy/tool/algo: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Apr 14 17:34:26 CEST 2010
Author: arigo
Date: Wed Apr 14 17:34:25 2010
New Revision: 73740
Modified:
pypy/branch/blackhole-improvement/pypy/tool/algo/color.py
pypy/branch/blackhole-improvement/pypy/tool/algo/test/test_color.py
Log:
Give a deterministic result instead of a random, dict-order-dependent one.
Modified: pypy/branch/blackhole-improvement/pypy/tool/algo/color.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/tool/algo/color.py (original)
+++ pypy/branch/blackhole-improvement/pypy/tool/algo/color.py Wed Apr 14 17:34:25 2010
@@ -2,10 +2,12 @@
class DependencyGraph(object):
def __init__(self):
+ self.nodes = []
self.neighbours = {}
def add_node(self, v):
assert v not in self.neighbours, "duplicate vertex %r" % (v,)
+ self.nodes.append(v)
self.neighbours[v] = set()
def add_edge(self, v1, v2):
@@ -14,20 +16,20 @@
def lexicographic_order(self):
"""Enumerate a lexicographic breath-first ordering of the nodes."""
- sigma = [set(self.neighbours)]
+ sigma = [self.nodes[:]]
while sigma:
v = sigma[0].pop()
yield v
newsigma = []
neighb = self.neighbours[v]
for s in sigma:
- s1 = set()
- s2 = set()
+ s1 = []
+ s2 = []
for x in s:
if x in neighb:
- s1.add(x)
+ s1.append(x)
else:
- s2.add(x)
+ s2.append(x)
if s1:
newsigma.append(s1)
if s2:
Modified: pypy/branch/blackhole-improvement/pypy/tool/algo/test/test_color.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/tool/algo/test/test_color.py (original)
+++ pypy/branch/blackhole-improvement/pypy/tool/algo/test/test_color.py Wed Apr 14 17:34:25 2010
@@ -22,12 +22,10 @@
order = list(dg.lexicographic_order())
assert len(order) == 5
order.reverse()
- assert ''.join(order) in [
- 'adbce', 'adbec', 'adcbe', 'adceb', 'adebc', 'adecb',
- 'acbde', 'acbed', 'acdbe', 'acdeb', 'acebd', 'acedb',
- 'cebad', 'cebda', 'ceabd', 'ceadb', 'cedba', 'cedab',
- 'cabde', 'cabed', 'cadbe', 'cadeb', 'caebd', 'caedb',
- ]
+ # there are many orders that are correct answers, but check that we get
+ # the following one, which is somehow the 'first' answer in the order
+ # of insertion of nodes.
+ assert ''.join(order) == 'acbde'
def test_size_of_largest_clique():
dg = graph1()
More information about the Pypy-commit
mailing list