QoL and metric value inverter

This commit is contained in:
2026-03-04 11:10:45 -06:00
parent 8dfe3607b1
commit f57ac7d6dc
30 changed files with 556 additions and 118 deletions

View File

@@ -81,10 +81,34 @@ class TestScorer:
assert len(result.scores) == 5
def test_scorer_zero_metric_kills_score(self, urban_domain):
"""A zero on a higher-is-better metric should drive composite to 0."""
scorer = Scorer(urban_domain)
combo = Combination(entities=[])
combo.id = 1
raw = {"speed": 60.0, "cost_efficiency": 0.0, "safety": 0.7,
raw = {"speed": 60.0, "cost_efficiency": 0.5, "safety": 0.0,
"availability": 0.8, "range_fuel": 400}
result = scorer.score_combination(combo, raw)
assert result.composite_score == 0.0
def test_lower_is_better_inverts_score(self, urban_domain):
"""cost_efficiency is lower_is_better: low raw value should score high."""
scorer = Scorer(urban_domain)
combo = Combination(entities=[])
combo.id = 1
# cost_efficiency: norm_min=0.01, norm_max=2.0, lower_is_better=True
# A low cost (0.02) should get a HIGH normalized score (near 1.0)
# A high cost (1.9) should get a LOW normalized score (near 0.0)
raw_cheap = {"speed": 60.0, "cost_efficiency": 0.02, "safety": 0.7,
"availability": 0.8, "range_fuel": 400}
raw_expensive = {"speed": 60.0, "cost_efficiency": 1.9, "safety": 0.7,
"availability": 0.8, "range_fuel": 400}
result_cheap = scorer.score_combination(combo, raw_cheap)
result_expensive = scorer.score_combination(combo, raw_expensive)
# Find the cost_efficiency score in each
cost_cheap = next(s for s in result_cheap.scores if s.metric_name == "cost_efficiency")
cost_expensive = next(s for s in result_expensive.scores if s.metric_name == "cost_efficiency")
assert cost_cheap.normalized_score > cost_expensive.normalized_score
assert cost_cheap.normalized_score > 0.9 # near the best
assert cost_expensive.normalized_score < 0.1 # near the worst