import pytest from engine.forecast import ForecastError, ForecastService class TestForecastService: def test_forecast_returns_results(self, sample_model): service = ForecastService(sample_model) results = service.forecast_cashflow(months=12) assert len(results) > 0 assert "balance" in results[0] assert "month" in results[0] def test_forecast_12_months(self, sample_model): service = ForecastService(sample_model) results = service.forecast_cashflow(months=12) months = set(r["month"] for r in results) assert max(months) == 12 def test_invalid_months(self, sample_model): service = ForecastService(sample_model) with pytest.raises(ForecastError): service.forecast_cashflow(months=0) def test_summary(self, sample_model): service = ForecastService(sample_model) s = service.summary(months=6) assert "total_balance" in s assert "total_income" in s assert "total_expenses" in s assert s["months"] == 6 def test_empty_model(self, empty_model): service = ForecastService(empty_model) results = service.forecast_cashflow(months=3) assert results == []