def test_distance(self): self.assertEqual(5, levenshtein_distance('kitten', 'sitting')) self.assertEqual(1, levenshtein_distance('wii', 'wiki')) self.assertEqual(2, levenshtein_distance('comfig', 'config')) self.assertEqual(5, levenshtein_distance('update', 'upgrade')) self.assertEqual(0, levenshtein_distance('milestone', 'milestone'))
def score(cmd, arg): if cmd.startswith(arg): return 0 return levenshtein_distance(cmd, arg) / float(len(cmd) + len(arg))
def test_distance(self): self.assertEqual(5, levenshtein_distance("kitten", "sitting")) self.assertEqual(1, levenshtein_distance("wii", "wiki")) self.assertEqual(2, levenshtein_distance("comfig", "config")) self.assertEqual(5, levenshtein_distance("update", "upgrade")) self.assertEqual(0, levenshtein_distance("milestone", "milestone"))