Skip to content

Commit

Permalink
add more sample inputs and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erdem committed Aug 16, 2024
1 parent c790165 commit 94c93eb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
17 changes: 17 additions & 0 deletions samples/input2.json
Original file line number Diff line number Diff line change
@@ -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
}
}
17 changes: 17 additions & 0 deletions samples/input3.json
Original file line number Diff line number Diff line change
@@ -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
}
}
Empty file added tests/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions tests/unit/test_calculators.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 94c93eb

Please sign in to comment.