Added test for abbrev and fixed a bug it found.

This commit is contained in:
Jeremy Fincher 2003-04-04 16:14:58 +00:00
parent 100d0fa016
commit e962cc1d77
2 changed files with 17 additions and 1 deletions

View File

@ -77,7 +77,8 @@ def abbrev(strings):
if abbreviation not in d:
d[abbreviation] = s
else:
d[abbreviation] = None
if abbreviation not in strings:
d[abbreviation] = None
removals = []
for key in d:
if d[key] is None:

View File

@ -62,3 +62,18 @@ class UtilsTest(unittest.TestCase):
self.assertEqual(utils.distance('a', 'ab'), 1)
self.assertEqual(utils.distance('foo', ''), 3)
self.assertEqual(utils.distance('', 'foo'), 3)
def testAbbrev(self):
L = ['abc', 'bcd', 'bbe', 'foo', 'fool']
d = utils.abbrev(L)
def getItem(s):
return d[s]
self.assertRaises(KeyError, getItem, 'f')
self.assertRaises(KeyError, getItem, 'fo')
self.assertRaises(KeyError, getItem, 'b')
self.assertEqual(d['bb'], 'bbe')
self.assertEqual(d['bc'], 'bcd')
self.assertEqual(d['a'], 'abc')
self.assertEqual(d['ab'], 'abc')
self.assertEqual(d['fool'], 'fool')
self.assertEqual(d['foo'], 'foo')