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