From 94c93eb938ec8855915cb77c908386c3e8a6d8dd Mon Sep 17 00:00:00 2001 From: erdem Date: Fri, 16 Aug 2024 15:31:43 +0100 Subject: [PATCH] add more sample inputs and unit tests --- samples/input2.json | 17 +++++++++++++++++ samples/input3.json | 17 +++++++++++++++++ tests/__init__.py | 0 tests/unit/test_calculators.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 samples/input2.json create mode 100644 samples/input3.json create mode 100644 tests/__init__.py diff --git a/samples/input2.json b/samples/input2.json new file mode 100644 index 0000000..97be0ac --- /dev/null +++ b/samples/input2.json @@ -0,0 +1,17 @@ +{ + "weather": { + "temperature": 25, + "humidity": 60.5, + "wind_speed": 10.2 + }, + "traffic_flow": { + "average_speed": 45.5, + "traffic_density": [0.3, 0.5, 0.7], + "incident_reports": 2 + }, + "road_condition": { + "road_quality": 8, + "lighting_conditions": 9, + "accident_history": 1 + } +} \ No newline at end of file diff --git a/samples/input3.json b/samples/input3.json new file mode 100644 index 0000000..66c3ecf --- /dev/null +++ b/samples/input3.json @@ -0,0 +1,17 @@ +{ + "weather": { + "temperature": -5, + "humidity": 90.5, + "wind_speed": 25.0 + }, + "traffic_flow": { + "average_speed": 10.5, + "traffic_density": [0.95, 0.98, 0.99], + "incident_reports": 10 + }, + "road_condition": { + "road_quality": 2, + "lighting_conditions": 3, + "accident_history": 7 + } +} diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/test_calculators.py b/tests/unit/test_calculators.py index e69de29..955cc82 100644 --- a/tests/unit/test_calculators.py +++ b/tests/unit/test_calculators.py @@ -0,0 +1,29 @@ +from src.calculators import ( + calculate_comfort_index, + calculate_traffic_flow_efficiency, + calculate_safety_score, + calculate_overall_commute_quality_score, +) + + +def test_calculate_comfort_index(): + assert calculate_comfort_index(25, 60) == 45 + assert calculate_comfort_index(30, 70, 10) == 25 + assert calculate_comfort_index(20, 50, 5) == 57.5 + + +def test_calculate_traffic_flow_efficiency(): + assert calculate_traffic_flow_efficiency(60, [0.5, 0.3, 0.2]) == 30.0 + assert calculate_traffic_flow_efficiency(50, [0.4, 0.4, 0.2], 2) == 21 + assert calculate_traffic_flow_efficiency(40, [0.1, 0.1], 0) == 33.333333333333336 + + +def test_calculate_safety_score(): + assert calculate_safety_score(8, 7, 2, 50, [0.3, 0.4, 0.3]) == 353.6666666666667 + assert calculate_safety_score(9, 8, 1, 60, [0.2, 0.2, 0.1], 3, 5) == 478.5 + assert calculate_safety_score(7, 6, 3, 40, [0.5, 0.5], 1) == 241.75 + + +def test_calculate_overall_commute_quality_score(): + assert calculate_overall_commute_quality_score(45, 60, 120) == 75 + assert calculate_overall_commute_quality_score(25, 21, 472) == 172.66666666666666