58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from app.business.travel_calc import (
|
|
compute_km_for_entry,
|
|
compute_co2_grams,
|
|
compute_frais_reels,
|
|
)
|
|
|
|
VEHICLES = {
|
|
"voiture": {"co2_per_km": 142, "cv": 5},
|
|
"velo": {"co2_per_km": 0},
|
|
}
|
|
|
|
JOURNEYS = {
|
|
"voiture_seule": {"distances": {"voiture": 25}},
|
|
"voiture_velo": {"distances": {"voiture": 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_voiture_seule():
|
|
assert compute_km_for_entry("voiture_seule", JOURNEYS) == {"voiture": 25}
|
|
|
|
|
|
def test_compute_km_voiture_velo():
|
|
assert compute_km_for_entry("voiture_velo", JOURNEYS) == {"voiture": 14, "velo": 8}
|
|
|
|
|
|
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_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
|