75 lines
1.9 KiB
Python
75 lines
1.9 KiB
Python
from app.business.travel_calc import (
|
|
compute_km_for_entry,
|
|
compute_co2_grams,
|
|
compute_frais_reels,
|
|
)
|
|
|
|
VEHICLES = {
|
|
"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 = {
|
|
"moteur_seul": {"distances": {"moteur": 25}},
|
|
"moteur_velo": {"distances": {"moteur": 14, "velo": 8}},
|
|
"velo_seul": {"distances": {"velo": 24}},
|
|
}
|
|
|
|
TRANCHES_CV5 = [
|
|
{"km_max": 3000, "taux": 0.548, "forfait": 0},
|
|
{"km_max": 6000, "taux": 0.316, "forfait": 699},
|
|
{"km_max": 0, "taux": 0.364, "forfait": 0},
|
|
]
|
|
|
|
|
|
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_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_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():
|
|
assert compute_co2_grams({"velo": 24}, VEHICLES) == 0
|
|
|
|
|
|
def test_frais_reels_tranche1():
|
|
result = compute_frais_reels(2000, TRANCHES_CV5)
|
|
assert abs(result - 1096.0) < 0.01
|
|
|
|
|
|
def test_frais_reels_tranche2():
|
|
result = compute_frais_reels(4000, TRANCHES_CV5)
|
|
assert abs(result - 1963.0) < 0.01
|
|
|
|
|
|
def test_frais_reels_tranche3():
|
|
result = compute_frais_reels(7000, TRANCHES_CV5)
|
|
assert abs(result - 2548.0) < 0.01
|