Selaa lähdekoodia

test: add tests of sorting first by score then by time

main
Rob Hallam 2 kuukautta sitten
vanhempi
commit
dfb5cbd1ef
1 muutettua tiedostoa jossa 56 lisäystä ja 0 poistoa
  1. +56
    -0
      test/test_adjusters.py

+ 56
- 0
test/test_adjusters.py Näytä tiedosto

@@ -119,3 +119,59 @@ class TestTargetTimeAdjuster(unittest.TestCase):
features.append(make_feature(duration=i*1.0))
tta = adjusters.TargetTimeAdjuster(features=features, target_time=10.0)
self.assertEqual(tta.adjust(), features)


def test_sort_by_score_time(self):
"""Test sorting of list of Features by score (primary) and time (secondary)

Cases:
- [(15.0, 1.0), (10.0, 1.0), (12.0, 1.0)] --> [(10.0, 1.0), (12.0, 1.0), (15.0, 1.0)] # score equal, sort by time
- [(15.0, 1.0), (10.0, 4.0), (12.0, 3.0)] --> [(15.0, 1.0), (12.0, 3.0), (10.0, 4.0)] # sort by score
- [(15.0, 1.0), (10.0, 1.0), (12.0, 2.0)] --> [(10.0, 1.0), (15.0, 1.0), (12.0, 2.0)] # mixed: scores below duration
- [] --> []
- [(15.0, 1.0)] --> [(15.0, 1.0)]

Cases giving RDH trouble:
- [(16.0, 1.0), (16.0, 1.0), (1.0, 1.0), (1.0, 1.0)] --> [(1.0, 1.0), (1.0, 1.0), (16.0, 1.0), (16.0, 1.0)] # multiple lowest scoring, multiple shortest duration
"""

tta = adjusters.TargetTimeAdjuster()
with self.subTest("score equal, sort by duration"):
features = [
make_feature(duration=15.0, score=1.0),
make_feature(duration=10.0, score=1.0),
make_feature(duration=12.0, score=1.0)
]
self.assertEqual(tta._sort_by_score_time(features), [features[1], features[2], features[0]])

with self.subTest("sort by score, duration irrelevant"):
features = [
make_feature(duration=15.0, score=1.0),
make_feature(duration=10.0, score=4.0),
make_feature(duration=12.0, score=3.0)
]
self.assertEqual(tta._sort_by_score_time(features), [features[0], features[2], features[1]])

with self.subTest("mixed: scores below duration"):
features = [
make_feature(duration=15.0, score=1.0),
make_feature(duration=10.0, score=1.0),
make_feature(duration=12.0, score=2.0)
]
self.assertEqual(tta._sort_by_score_time(features), [features[1], features[0], features[2]])

with self.subTest("empty"):
self.assertEqual(tta._sort_by_score_time([]), [])

with self.subTest("single"):
features = [mock.Mock(duration=15.0, score=1.0)]
self.assertEqual(tta._sort_by_score_time(features), features)

with self.subTest("multiple lowest scoring, multiple shortest duration"):
features = [
make_feature(duration=16.0, score=1.0),
make_feature(duration=16.0, score=1.0),
make_feature(duration=1.0, score=1.0),
make_feature(duration=1.0, score=1.0)
]
self.assertEqual(tta._sort_by_score_time(features), [features[2], features[3], features[0], features[1]])

Ladataan…
Peruuta
Tallenna