69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
"""Tests for IIHS and US NCAP scoring."""
|
|
|
|
import pytest
|
|
|
|
from impakt.criteria.base import CriterionResult
|
|
from impakt.protocol.iihs import IIHS, evaluate as iihs_evaluate
|
|
from impakt.protocol.us_ncap import USNCAP, evaluate as us_evaluate
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_criteria():
|
|
return {
|
|
"HIC15": CriterionResult(criterion="HIC15", value=400, body_region="Head"),
|
|
"Nij": CriterionResult(criterion="Nij", value=0.4, body_region="Neck"),
|
|
"Chest Deflection": CriterionResult(
|
|
criterion="Chest Deflection", value=35, unit="mm", body_region="Chest"
|
|
),
|
|
"Femur Load Left": CriterionResult(
|
|
criterion="Femur Load Left", value=4.0, unit="kN", body_region="Femur Left"
|
|
),
|
|
"Femur Load Right": CriterionResult(
|
|
criterion="Femur Load Right", value=4.5, unit="kN", body_region="Femur Right"
|
|
),
|
|
}
|
|
|
|
|
|
class TestIIHS:
|
|
def test_good_results(self, sample_criteria):
|
|
result = iihs_evaluate(sample_criteria)
|
|
assert result.protocol == "IIHS"
|
|
assert result.overall_rating in ("GOOD", "ACCEPTABLE", "MARGINAL", "POOR")
|
|
|
|
def test_region_scores(self, sample_criteria):
|
|
result = iihs_evaluate(sample_criteria)
|
|
assert len(result.region_scores) > 0
|
|
for rs in result.region_scores:
|
|
assert rs.rating is not None
|
|
|
|
def test_poor_hic(self):
|
|
result = iihs_evaluate(
|
|
{
|
|
"HIC15": CriterionResult(criterion="HIC15", value=1500, body_region="Head"),
|
|
}
|
|
)
|
|
assert result.overall_rating == "POOR"
|
|
|
|
def test_summary(self, sample_criteria):
|
|
result = iihs_evaluate(sample_criteria)
|
|
summary = result.summary()
|
|
assert "IIHS" in summary
|
|
|
|
|
|
class TestUSNCAP:
|
|
def test_basic(self, sample_criteria):
|
|
result = us_evaluate(sample_criteria)
|
|
assert result.protocol == "US NCAP"
|
|
assert result.stars is not None
|
|
assert 1 <= result.stars <= 5
|
|
|
|
def test_injury_probabilities(self, sample_criteria):
|
|
result = us_evaluate(sample_criteria)
|
|
assert "combined_injury_probability" in result.details
|
|
p = result.details["combined_injury_probability"]
|
|
assert 0.0 <= p <= 1.0
|
|
|
|
def test_region_scores(self, sample_criteria):
|
|
result = us_evaluate(sample_criteria)
|
|
assert len(result.region_scores) > 0
|