SPB Git
3.2 KB · 60 lines python
1"""Chapitre 16 — vérification des chiffres cités dans le texte et les solutions."""2import sys, pathlib, math3import numpy as np, pytest4sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "cases"))5import ch16_selection as c166from traite import comparables as cp78@pytest.fixture(scope="module")9def res():10    return c16.main(figures=False)1112def test_entonnoir_et_comparables(res):13    e = res["selection"]["etapes"]14    assert e == {"candidats_total": 600, "apres_delai": 236, "apres_rayon": 40, "apres_type": 27, "apres_superficie": 16}15    top = res["selection"]["comparables"]16    assert list(top["id_vente"]) == ["G0574", "G0404", "G0468", "G0477", "G0575"]17    assert (top["secteur"] == "Hull").all() and (top["mois"] <= 18).all() and (top["dist_km"] <= 3).all()18    assert list(top["prix_vente"]) == [598000, 506500, 624500, 538000, 513500]1920def test_indication_brute(res):21    top = res["selection"]["comparables"]; s = res["sujet"]22    ind = top["prix_m2"].median() * s["superficie_habitable_m2"]23    assert ind == pytest.approx(551029, abs=1)24    assert top["prix_vente"].min() == 506500 and top["prix_vente"].max() == 62450025    assert top["prix_vente"].mean() == pytest.approx(556100) and top["prix_vente"].median() == 53800026    cand = res["selection"]["candidats"]27    assert cand["prix_m2"].median() == pytest.approx(3286, abs=1) and cand["prix_m2"].min() == pytest.approx(2361, abs=1) and cand["prix_m2"].max() == pytest.approx(4140, abs=1)2829def test_sensibilite(res):30    s = res["sensibilite"]31    assert len(s) == 4832    assert s.indication_m2.min() == pytest.approx(525768, abs=1) and s.indication_m2.max() == pytest.approx(608014, abs=1)33    assert s.indication_m2.std() == pytest.approx(24069, abs=2)34    g = s.groupby("k").indication_m2.agg(["min", "median", "max"])35    assert g.loc[4, "median"] == pytest.approx(579522, abs=1) and g.loc[10, "max"] == pytest.approx(596921, abs=1)3637def test_solutions_exercices():38    # ex. 16.139    pu = [525000 / 152, 489000 / 141, 561000 / 171]40    assert sorted(pu)[1] * 165 == pytest.approx(569902, abs=1)41    # ex. 16.342    e = {"s": 25, "t": 150, "a": 10, "q": 1}; w = {"s": 2, "t": 0.7, "a": 1, "q": 1}43    suj = {"s": 165, "t": 620, "a": 28, "q": 3}44    dA = cp.distance_attributs(suj, {"s": 158, "t": 600, "a": 25, "q": 3}, e, w)45    dB = cp.distance_attributs(suj, {"s": 190, "t": 650, "a": 10, "q": 4}, e, w)46    dC = cp.distance_attributs(suj, {"s": 150, "t": 400, "a": 30, "q": 2}, e, w)47    assert dA == pytest.approx(0.509, abs=0.001) and dB == pytest.approx(2.504, abs=0.001) and dC == pytest.approx(1.807, abs=0.001)48    # ex. 16.449    assert 506500 * (1.0443 ** (15 / 12) - 1) == pytest.approx(28200, rel=0.01)50    # ex. 16.551    inv = [1 / 20**2, 1 / 30**2, 1 / 40**2]; S = sum(inv)52    assert [x / S for x in inv] == pytest.approx([0.590, 0.262, 0.148], abs=0.001)53    assert math.sqrt(1 / S) == pytest.approx(15.4, abs=0.05) and math.sqrt((400 + 900 + 1600) / 9) == pytest.approx(17.95, abs=0.01)54    # ex. 16.755    k = (25000**2 / (2 * 2000**2)) ** (1 / 3)56    assert k == pytest.approx(4.27, abs=0.01)57    assert (25000**2 / (2 * 500**2)) ** (1 / 3) == pytest.approx(10.8, abs=0.05)58    eqm = 2000**2 * 16 + 25000**2 / 459    assert math.sqrt(eqm) == pytest.approx(14800, rel=0.01)60
Files · main
Menu

Theme