From ea26e6660e85048e3e7930a8bd2c78aad0ec9889 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 22 Sep 2010 20:23:36 -0700 Subject: [PATCH] fix a bug where string heuristics could penalize --- beets/autotag/__init__.py | 4 +++- test/test_autotag.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index ce3cbde23..4fb9b6f5c 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -198,7 +198,9 @@ def string_dist(str1, str2): # the current case), recalculate the distances for the # modified strings. case_dist = _string_dist_basic(case_str1, case_str2) - case_delta = max(0, base_dist - case_dist) + case_delta = max(0.0, base_dist - case_dist) + if case_delta == 0.0: + continue # Shift our baseline strings down (to avoid rematching the # same part of the string) and add a scaled distance diff --git a/test/test_autotag.py b/test/test_autotag.py index 466b84d29..29e950eb0 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -305,6 +305,10 @@ class StringDistanceTest(unittest.TestCase): autotag.string_dist('(EP)', '(EP)') autotag.string_dist(', An', '') + def test_heuristic_does_not_harm_distance(self): + dist = autotag.string_dist('Untitled', '[Untitled]') + self.assertEqual(dist, 0.0) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)