mirror of
https://github.com/fergalmoran/picard.git
synced 2026-05-20 01:46:07 +00:00
PICARD-2805: Handle None length in Metadata.length_score
This commit is contained in:
@@ -206,6 +206,8 @@ class Metadata(MutableMapping):
|
||||
|
||||
@staticmethod
|
||||
def length_score(a, b):
|
||||
if a is None or b is None:
|
||||
return 0.0
|
||||
return (1.0 - min(abs(a - b),
|
||||
LENGTH_SCORE_THRES_MS) / float(LENGTH_SCORE_THRES_MS))
|
||||
|
||||
|
||||
@@ -311,7 +311,10 @@ class CommonTests:
|
||||
(20000, 20000, 1.0),
|
||||
(20000, 30000, 0.666666666667),
|
||||
(20000, 40000, 0.333333333333),
|
||||
(20000, 50000, 0.0)]
|
||||
(20000, 50000, 0.0),
|
||||
(20000, None, 0.0),
|
||||
(None, 2000, 0.0),
|
||||
(None, None, 0.0)]
|
||||
for (a, b, expected) in results:
|
||||
actual = Metadata.length_score(a, b)
|
||||
self.assertAlmostEqual(expected, actual,
|
||||
|
||||
Reference in New Issue
Block a user