import pytest from traite import cout as c def test_cout_neuf_conventions(): a = c.cout_neuf(1_000_000, 0.12, 0.10, "direct+indirect") assert a["indirects"] == 120_000 and a["incitatif"] == pytest.approx(112_000) and a["total"] == pytest.approx(1_232_000) b = c.cout_neuf(1_000_000, 0.12, 0.10, "direct") assert b["incitatif"] == 100_000 def test_indexation_et_taille(): assert c.indexer_cout(1000, 100, 125) == 1250 # élasticité −0,1 : doubler la superficie réduit le coût unitaire de ~6,7 % assert c.cout_par_superficie_ajuste(2000, 150, 300, -0.1) == pytest.approx(2000 * 2 ** -0.1) def test_age_vie_bornes(): assert c.depreciation_age_vie(500_000, 15, 60) == 125_000 assert c.depreciation_age_vie(500_000, 90, 60) == 500_000 m = c.depreciation_age_vie_modifiee(500_000, 20_000, 15, 60) assert m["total"] == pytest.approx(20_000 + 480_000 * 0.25) def test_ventilee_sans_double_comptage(): comps = [c.Composante("toiture", 30_000, 10, 20), c.Composante("chauffage", 20_000, 5, 20)] d = c.depreciation_ventilee(500_000, 10_000, comps, 20, 70) assert d["courte_duree"]["toiture"] == 15_000 and d["courte_duree"]["chauffage"] == 5_000 assert d["base_longue"] == 500_000 - 10_000 - 50_000 assert d["total"] == pytest.approx(10_000 + 20_000 + 440_000 * 20 / 70) def test_desuetudes(): assert c.desuetude_fonctionnelle_curable(12_000, 8_000, 1_000) == 3_000 assert c.desuetude_incurable_par_loyer(150, 120) == 18_000 assert c.desuetude_incurable_par_rne(6_000, 0.06, 0.8) == pytest.approx(80_000) assert c.desuetude_externe_ventes_appariees(500_000, 470_000, 0.75) == 22_500 def test_extraction_marche_et_valeur(): e = c.extraction_depreciation_marche(520_000, 150_000, 480_000, 20) assert e["depreciation"] == 110_000 and e["taux"] == pytest.approx(110_000 / 480_000) and e["taux_annuel"] == pytest.approx(110_000 / 480_000 / 20) v = c.valeur_par_cout(150_000, 480_000, 80_000, 10_000, 20_000, 15_000) assert v["valeur"] == 150_000 + 480_000 - 110_000 + 15_000 assert v["taux_depreciation"] == pytest.approx(110_000 / 480_000)