From e92b8bb8fbcca499ca4566c87e524d9e83fcc3a8 Mon Sep 17 00:00:00 2001 From: Tai Lee Date: Mon, 3 Jun 2013 14:49:39 +1000 Subject: [PATCH] Fix `add_priority()` calculation. We were incorrectly adding 1 to the length of options to avoid a divide by zero, when we should instead default the length to 1. Otherwise we skew the penalty towards zero. --- beets/autotag/match.py | 2 +- test/test_autotag.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/beets/autotag/match.py b/beets/autotag/match.py index 813105910..ebf781421 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -279,7 +279,7 @@ class Distance(object): """ if not isinstance(options, (list, tuple)): options = [options] - unit = 1.0 / (len(options) + 1) + unit = 1.0 / (len(options) or 1) for i, opt in enumerate(options): if self._eq(opt, value): dist = i * unit diff --git a/test/test_autotag.py b/test/test_autotag.py index f2dcbbc28..c513dc530 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -151,15 +151,15 @@ class DistanceTest(unittest.TestCase): self.dist.add_priority('priority', 'abc', 'abc') self.assertEqual(self.dist._penalties['priority'], [0.0]) - self.dist.add_priority('priority', 'def', ['abc', 'def', 'ghi']) - self.assertEqual(self.dist._penalties['priority'], [0.0, 0.25]) + self.dist.add_priority('priority', 'def', ['abc', 'def']) + self.assertEqual(self.dist._penalties['priority'], [0.0, 0.5]) - self.dist.add_priority('priority', 'ghi', ['abc', 'def', - re.compile('GHI', re.I)]) - self.assertEqual(self.dist._penalties['priority'], [0.0, 0.25, 0.5]) + self.dist.add_priority('priority', 'gh', ['ab', 'cd', 'ef', + re.compile('GH', re.I)]) + self.assertEqual(self.dist._penalties['priority'], [0.0, 0.5, 0.75]) self.dist.add_priority('priority', 'xyz', ['abc', 'def']) - self.assertEqual(self.dist._penalties['priority'], [0.0, 0.25, 0.5, + self.assertEqual(self.dist._penalties['priority'], [0.0, 0.5, 0.75, 1.0]) def test_add_ratio(self):