From a8ccff31a03232bd669b4c0e633c577558a071de Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Mar 2026 16:59:03 +0000 Subject: [PATCH] Add YoY edge case tests for 5 and 4 quarter scenarios Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com> Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/b594017b-ed84-4786-9b81-200a78eb5d76 --- tests/unit/test_ttm_analysis.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/unit/test_ttm_analysis.py b/tests/unit/test_ttm_analysis.py index 224fe932..f4f4106c 100644 --- a/tests/unit/test_ttm_analysis.py +++ b/tests/unit/test_ttm_analysis.py @@ -174,6 +174,25 @@ class TestComputeTTMMetrics: expected_yoy = ((1.05 ** 4) - 1) * 100 assert abs(yoy - expected_yoy) < 0.5 + def test_revenue_yoy_with_exactly_5_quarters(self): + """YoY is available when exactly 5 quarters exist (minimum for 4-quarter lookback).""" + result = self.compute( + _make_income_csv(5), _make_balance_csv(5), _make_cashflow_csv(5) + ) + yoy = result["trends"]["revenue_yoy_pct"] + assert yoy is not None + # quarterly[-5] vs quarterly[-1] with 5% QoQ → 1.05^4 - 1 ≈ 21.55% + expected_yoy = ((1.05 ** 4) - 1) * 100 + assert abs(yoy - expected_yoy) < 0.5 + + def test_revenue_yoy_none_with_4_quarters(self): + """YoY should be None when fewer than 5 quarters are available.""" + result = self.compute( + _make_income_csv(4), _make_balance_csv(4), _make_cashflow_csv(4) + ) + yoy = result["trends"]["revenue_yoy_pct"] + assert yoy is None + def test_margin_trend_expanding(self): """Expanding margin should be detected.""" # Create data where net margin expands over time