mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added test for abbrev and fixed a bug it found.
This commit is contained in:
parent
100d0fa016
commit
e962cc1d77
@ -77,6 +77,7 @@ def abbrev(strings):
|
|||||||
if abbreviation not in d:
|
if abbreviation not in d:
|
||||||
d[abbreviation] = s
|
d[abbreviation] = s
|
||||||
else:
|
else:
|
||||||
|
if abbreviation not in strings:
|
||||||
d[abbreviation] = None
|
d[abbreviation] = None
|
||||||
removals = []
|
removals = []
|
||||||
for key in d:
|
for key in d:
|
||||||
|
@ -62,3 +62,18 @@ class UtilsTest(unittest.TestCase):
|
|||||||
self.assertEqual(utils.distance('a', 'ab'), 1)
|
self.assertEqual(utils.distance('a', 'ab'), 1)
|
||||||
self.assertEqual(utils.distance('foo', ''), 3)
|
self.assertEqual(utils.distance('foo', ''), 3)
|
||||||
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