import pytest, numpy as np from traite import cas3, finance as fin def test_cas3_identites(): r = cas3.tout(); b = r["base"]; p = r["projection"]; h = r["hyp"] assert b["rbe"] == pytest.approx(b["rbp_contrat"] * (1 - b["taux_vacance_pertes"]) + b["autres_revenus"]) assert b["rne"] == pytest.approx(b["rbe"] - b["depenses_totales"]) assert len(p) == h["horizon_ans"] + 1 and (p["rne"] > 0).all() assert p.loc[0, "rne"] == pytest.approx(b["rne"], rel=1e-9) # année 1 = RNE normalisé assert (p["rbp"].diff().dropna() > 0).all() # loyers croissants assert (p["rbp"] <= p["rbp_marche"] + 1e-6).all() # jamais au-dessus du marché d = r["dcf"]; flux = d["flux"] va = sum(cf / (1 + h["taux_actualisation"]) ** (t + 1) for t, cf in enumerate(flux)) + d["vt_nette"] / (1 + h["taux_actualisation"]) ** h["horizon_ans"] assert d["valeur"] == pytest.approx(va) assert d["vt_brute"] == pytest.approx(d["rne_T1"] / h["taux_terminal"]) and d["vt_nette"] == pytest.approx(d["vt_brute"] * (1 - h["couts_vente"])) f = r["financement"] assert f["rcd"] >= h["financement"]["rcd_min"] - 1e-9 and f["rpv"] <= h["financement"]["rpv"] + 1e-9 assert 0.03 < r["taux"]["mediane"] < 0.07 and r["taux"]["n"] >= 10 assert 0.5 < r["valeur_capitalisation"] / d["valeur"] < 1.5