mirror of
https://github.com/beetbox/beets.git
synced 2025-12-30 20:42:37 +01:00
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.
This commit is contained in:
parent
0c27d275f3
commit
e92b8bb8fb
2 changed files with 7 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue