46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
from apps.jobs.services.distance import CommuteEstimate, estimate_commute, haversine_km
|
|
from apps.jobs.services.features import extract_deterministic_features, term_ratio
|
|
|
|
|
|
def test_feature_extraction_and_distance_are_deterministic():
|
|
text = (
|
|
"Voor een gemeente zoeken we een consultant. Rijbewijs B en 5 jaar ervaring vereist. "
|
|
"De rol bevat helpdesk en telefonische support bij klanten."
|
|
)
|
|
features = extract_deterministic_features("Support Engineer", text)
|
|
assert features["support_ratio"] > 0
|
|
assert features["consultancy_ratio"] > 0
|
|
assert features["travel_ratio"] > 0
|
|
assert features["public_sector_signal"] > 0
|
|
assert features["experience_years_max"] == 5
|
|
assert term_ratio("", ["x"]) == 0
|
|
assert 60 < haversine_km(50.9307, 5.3325, 50.8503, 4.3517) < 80
|
|
|
|
|
|
def test_conservative_commute_estimate_is_marked_as_estimate():
|
|
result = estimate_commute(20.0)
|
|
assert isinstance(result, CommuteEstimate)
|
|
assert result.is_estimate
|
|
assert result.minutes > 0
|
|
assert result.source == "road"
|
|
|
|
|
|
def test_custom_commute_estimator_is_accepted():
|
|
class CustomEstimator:
|
|
name = "custom"
|
|
version = "test"
|
|
|
|
def estimate(self, distance_km: float) -> CommuteEstimate:
|
|
return CommuteEstimate(
|
|
minutes=int(distance_km * 2),
|
|
km=distance_km,
|
|
source=self.name,
|
|
source_version=self.version,
|
|
confidence=0.7,
|
|
is_estimate=False,
|
|
)
|
|
|
|
result = estimate_commute(12.0, estimator=CustomEstimator())
|
|
assert result.minutes == 24
|
|
assert result.source_version == "test"
|