Implementiert Task 5 mit TDD-Ansatz: projection.py mit Projection-Klasse und project()-Funktion für Cashflow-Simulation; scenario.py mit PlainRecurring, PlainPlanned, PlainModifier Dataclasses und build_cashflows() für Szenarien-Zahlungsströme mit Modifier-Support (remove, percent, absolute). Alle 15 Tests grün. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
38 lines
1.8 KiB
Python
38 lines
1.8 KiB
Python
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
from app.engine.loans import loan_schedule
|
|
from app.engine.scenario import (PlainModifier, PlainPlanned, PlainRecurring,
|
|
build_cashflows)
|
|
|
|
W = (date(2026, 8, 1), date(2026, 10, 31))
|
|
|
|
|
|
def test_recurring_with_percent_cut():
|
|
rec = [PlainRecurring(id=1, name="Marketing", amount=Decimal("-1000"),
|
|
rhythm="monthly", due_day=5, start_date=None,
|
|
end_date=None, category_id=7)]
|
|
mods = [PlainModifier(target_type="category", target_id=7,
|
|
kind="percent", value=Decimal("50"))]
|
|
flows = build_cashflows(rec, [], [], [], mods, *W)
|
|
assert flows == [(date(2026, 8, 5), Decimal("-500.00")),
|
|
(date(2026, 9, 5), Decimal("-500.00")),
|
|
(date(2026, 10, 5), Decimal("-500.00"))]
|
|
|
|
|
|
def test_remove_modifier_and_planned_and_loan():
|
|
rec = [PlainRecurring(id=2, name="Abo", amount=Decimal("-50"),
|
|
rhythm="monthly", due_day=1, start_date=None,
|
|
end_date=None, category_id=None)]
|
|
mods = [PlainModifier(target_type="recurring", target_id=2,
|
|
kind="remove", value=Decimal("0"))]
|
|
planned = [PlainPlanned(name="Steuer", amount=Decimal("-2000"),
|
|
due=date(2026, 9, 15), category_id=None)]
|
|
sched = loan_schedule(Decimal("10000"), Decimal("6"), 48, date(2026, 8, 1), "annuity")
|
|
flows = build_cashflows(rec, planned, [sched],
|
|
[(date(2026, 8, 1), Decimal("10000"))], mods, *W)
|
|
days = [d for d, _ in flows]
|
|
assert date(2026, 8, 1) in days # Kredit-Auszahlung
|
|
assert date(2026, 9, 15) in days # Einmalposten
|
|
assert all(a != Decimal("-50") for _, a in flows) # Abo entfernt
|