mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Added test for abbrev and fixed a bug it found.
This commit is contained in:
parent
100d0fa016
commit
e962cc1d77
@ -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:
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user