Skip to content

Commit

Permalink
Merging Update fuzzy_string_cmp.py #2580
Browse files Browse the repository at this point in the history
  • Loading branch information
andresriancho committed Jun 4, 2014
1 parent 8362f5e commit e724007
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion w3af/core/controllers/misc/fuzzy_string_cmp.py
Expand Up @@ -116,7 +116,7 @@ def relative_distance(a_str, b_str):
#
return difflib.SequenceMatcher(None, a_str, b_str).quick_ratio()

return len(set_a.intersection(set_b)) / max(len(set_a), len(set_b))
return 1.0 * len(set_a.intersection(set_b)) / max(len(set_a), len(set_b))


def _generate_upper_bounds():
Expand Down
14 changes: 14 additions & 0 deletions w3af/core/controllers/misc/tests/test_fuzzy_string_cmp.py
Expand Up @@ -68,3 +68,17 @@ def test_all(self):
' - Threshold: %s\n'\

self.assertEqual(res1, res2, msg % (e, d, f))

def test_relative_distance(self):
acceptance_tests = []
acceptance_tests.append(('a', 'a', 1.0))
acceptance_tests.append(('ab ac ad', 'ab ae ad', 0.6))
acceptance_tests.append(('ab ac ae', 'ab af ad', 0.3))
acceptance_tests.append(('ab ac ad', 'aa ae af', 0.0))
acceptance_tests.append(('a', 'b', 0.0))
acceptance_tests.append(('aaaa', 'aaab', 0.75))
acceptance_tests.append(('a' * 25, 'a', 0.04))
for e, d, f in acceptance_tests:
res = relative_distance(e, d)
msg = "return value:%f, given value:%f" % (res, f)
self.assertTrue(res >= f, msg)

0 comments on commit e724007

Please sign in to comment.