Found bug in utils.sortBy, mentioned by Tim Peters on Python-dev. Fixed, and tested.

This commit is contained in:
Jeremy Fincher 2003-10-14 03:47:35 +00:00
parent 2bb8f950a2
commit b692681e1c
2 changed files with 5 additions and 2 deletions

View File

@ -323,10 +323,10 @@ def be(i):
def sortBy(f, L, cmp=cmp):
"""Uses the decorate-sort-undecorate pattern to sort L by function f."""
for (i, elt) in enumerate(L):
L[i] = (f(elt), elt)
L[i] = (f(elt), i, elt)
L.sort(cmp)
for (i, elt) in enumerate(L):
L[i] = L[i][1]
L[i] = L[i][2]
def mktemp(suffix=''):
"""Gives a decent random string, suitable for a filename."""

View File

@ -177,6 +177,9 @@ class UtilsTest(unittest.TestCase):
self.assertEqual(L, ['z', 'AD', 'abc'])
utils.sortBy(str.lower, L)
self.assertEqual(L, ['abc', 'AD', 'z'])
L = ['supybot', 'Supybot']
utils.sortBy(str.lower, L)
self.assertEqual(L, ['supybot', 'Supybot'])
def testNItems(self):
self.assertEqual(utils.nItems(1, 'tool', 'crazy'), '1 crazy tool')