mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
Found bug in utils.sortBy, mentioned by Tim Peters on Python-dev. Fixed, and tested.
This commit is contained in:
parent
2bb8f950a2
commit
b692681e1c
@ -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."""
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user