feat: compute_km_for_entry resolves generic moteur key to specific vehicle
This commit is contained in:
@@ -5,13 +5,14 @@ from app.business.travel_calc import (
|
||||
)
|
||||
|
||||
VEHICLES = {
|
||||
"voiture": {"co2_per_km": 142, "cv": 5},
|
||||
"velo": {"co2_per_km": 0},
|
||||
"familiale": {"co2_per_km": 142, "cv": 5, "type": "moteur"},
|
||||
"citadine": {"co2_per_km": 0, "cv": 3, "type": "moteur"},
|
||||
"velo": {"co2_per_km": 0, "type": "velo"},
|
||||
}
|
||||
|
||||
JOURNEYS = {
|
||||
"voiture_seule": {"distances": {"voiture": 25}},
|
||||
"voiture_velo": {"distances": {"voiture": 14, "velo": 8}},
|
||||
"moteur_seul": {"distances": {"moteur": 25}},
|
||||
"moteur_velo": {"distances": {"moteur": 14, "velo": 8}},
|
||||
"velo_seul": {"distances": {"velo": 24}},
|
||||
}
|
||||
|
||||
@@ -22,20 +23,36 @@ TRANCHES_CV5 = [
|
||||
]
|
||||
|
||||
|
||||
def test_compute_km_voiture_seule():
|
||||
assert compute_km_for_entry("voiture_seule", JOURNEYS) == {"voiture": 25}
|
||||
def test_compute_km_moteur_seul_avec_vehicule():
|
||||
km = compute_km_for_entry("moteur_seul", JOURNEYS, "familiale")
|
||||
assert km == {"familiale": 25}
|
||||
|
||||
|
||||
def test_compute_km_voiture_velo():
|
||||
assert compute_km_for_entry("voiture_velo", JOURNEYS) == {"voiture": 14, "velo": 8}
|
||||
def test_compute_km_moteur_velo_avec_vehicule():
|
||||
km = compute_km_for_entry("moteur_velo", JOURNEYS, "citadine")
|
||||
assert km == {"citadine": 14, "velo": 8}
|
||||
|
||||
|
||||
def test_compute_km_velo_seul():
|
||||
km = compute_km_for_entry("velo_seul", JOURNEYS)
|
||||
assert km == {"velo": 24}
|
||||
|
||||
|
||||
def test_compute_km_sans_vehicule_moteur_ignore():
|
||||
km = compute_km_for_entry("moteur_seul", JOURNEYS, None)
|
||||
assert km == {}
|
||||
|
||||
|
||||
def test_compute_km_no_journey():
|
||||
assert compute_km_for_entry(None, JOURNEYS) == {}
|
||||
|
||||
|
||||
def test_compute_co2_voiture():
|
||||
assert compute_co2_grams({"voiture": 25}, VEHICLES) == 25 * 142
|
||||
def test_compute_co2_familiale():
|
||||
assert compute_co2_grams({"familiale": 25}, VEHICLES) == 25 * 142
|
||||
|
||||
|
||||
def test_compute_co2_citadine_electrique():
|
||||
assert compute_co2_grams({"citadine": 25}, VEHICLES) == 0
|
||||
|
||||
|
||||
def test_compute_co2_velo():
|
||||
|
||||
Reference in New Issue
Block a user