From 4ffe712ce25859a4951199bcd5d2e6f84fd29b85 Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Tue, 3 Sep 2024 13:47:10 +0100 Subject: [PATCH] test: [TTA] add unit tests for _determine_margin -- ABSOLUTE --- test/test_adjusters.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/test_adjusters.py b/test/test_adjusters.py index f03b7d2..7e0f40b 100644 --- a/test/test_adjusters.py +++ b/test/test_adjusters.py @@ -41,3 +41,36 @@ class TestTargetTimeAdjuster(unittest.TestCase): self.assertEqual(tta._features_total_time(features), 10.0) self.assertEqual(tta._features_total_time([]), 0.0) self.assertIs(type(tta._features_total_time([])), float) + + def test_determine_margin(self): + """Test the TTA can determine the target time margins + + Args: time, margin, strategy (strategy in: ABSOLUTE, PERCENT) + + Test: + - margin of zero + - margin of 5.0 + - margin of 10.0 + - margin of 100.0 + - both ABSOLUTE and PERCENT strategies + + TODO: figure out what should be done with negative margins & margins > 100.0 + """ + + tta = adjusters.TargetTimeAdjuster() + with self.subTest("ABSOLUTE"): + strategy = adjusters.TargetTimeAdjuster._STRATEGY.ABSOLUTE + test_cases = [] + # populate test cases with tuples of (time, margin, expected) + # zero margin + test_cases.append((60.0, 0.0, (60.0, 60.0))) + # margin of 5.0 + test_cases.append((60.0, 5.0, (55.0, 65.0))) + # margin of 10.0 + test_cases.append((60.0, 10.0, (50.0, 70.0))) + # margin of 100.0 + test_cases.append((60.0, 100.0, (0.0, 160.0))) + + # test + for time, margin, expected in test_cases: + self.assertEqual(tta._determine_margin(time, margin, strategy), expected)