From 271c7fa8586ad98ba627eee05f818c11c9df6f10 Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Sun, 26 Aug 2007 09:41:05 +0000 Subject: [PATCH] fixed small but crucial cmp test bug when repopulating the stack --- direct/src/showbase/LazySort.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/direct/src/showbase/LazySort.py b/direct/src/showbase/LazySort.py index 2c0c622473..9f8a45050b 100755 --- a/direct/src/showbase/LazySort.py +++ b/direct/src/showbase/LazySort.py @@ -57,7 +57,7 @@ def itersorted(iterable, cmp = cmp, key = lambda x: x, reverse = False): # If init, get the first value and stop. # Otherwise, find the first value 'to the right' # of the most recently yielded value. - while (not init) and (cmp(k,lLimit) == -rev): + while (not init) and (cmp(k,lLimit) != rev): k,val = a.next() pass @@ -89,7 +89,6 @@ def itersorted(iterable, cmp = cmp, key = lambda x: x, reverse = False): layer[2].append(val) pass pass - # Remove the initialization condition to enable lLimit checking. init = False @@ -104,9 +103,22 @@ def itersorted(iterable, cmp = cmp, key = lambda x: x, reverse = False): yield val pass +def test(): + import random + from itertools import islice + + control = sorted(data, key = lambda x: x[0]) + variable = itersorted(data, key = lambda x: x[0]) + + print control[:10] == [x for x in islice(variable,10)] + print data + print control + + variable = itersorted(data, key = lambda x: x[0]) + print [x for x in islice(variable,10)] if __debug__: - def pp(i): - for x in i: + def P(i): + for x in reversed(i): print x from unittest import TestCase, main @@ -119,16 +131,16 @@ if __debug__: > python LazySort.py """ - RANGELEN = 10 - TESTLEN = 10 + TESTLEN = 1000 + RANGELEN = max(TESTLEN, 1000) - a = range(RANGELEN) - b = range(RANGELEN) + a = range(RANGELEN/2)*2 + b = range(RANGELEN/2)*2 shuffle(a) shuffle(b) DATA = zip(a,b) shuffle(DATA) - + DATA = [(2, 0), (2, 2), (4, 0), (3, 1), (1, 1), (0, 3), (0, 2), (4, 3), (3, 4), (1, 4)] del a del b