57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
"""Unit tests for ScenarioComparator (fleet sizing and dispatch policy parameter sweeps)."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from warehouse_twin.analytics.experiment_runner import ScenarioComparator
|
|
|
|
|
|
def test_compare_fleet_sizes(tmp_path: Path) -> None:
|
|
"""ScenarioComparator should run fleet size sweep and generate markdown report."""
|
|
comparator = ScenarioComparator()
|
|
report_file = tmp_path / "fleet_comparison.md"
|
|
|
|
res = comparator.compare_fleet_sizes(
|
|
fleet_sizes=[2, 4],
|
|
seed=42,
|
|
duration=120.0,
|
|
output_report=report_file,
|
|
)
|
|
|
|
assert res.scenario_type == "fleet_size"
|
|
assert len(res.experiments) == 2
|
|
assert len(res.comparison_table) == 2
|
|
assert res.comparison_table[0]["fleet_size"] == 2
|
|
assert res.comparison_table[1]["fleet_size"] == 4
|
|
|
|
assert report_file.exists()
|
|
content = report_file.read_text(encoding="utf-8")
|
|
assert "Scenario Comparison: Fleet Sizing Analysis" in content
|
|
assert "2 AMRs" in content
|
|
assert "4 AMRs" in content
|
|
|
|
|
|
def test_compare_dispatch_policies(tmp_path: Path) -> None:
|
|
"""ScenarioComparator should evaluate dispatch heuristics under identical workloads."""
|
|
comparator = ScenarioComparator()
|
|
report_file = tmp_path / "policy_comparison.md"
|
|
|
|
res = comparator.compare_dispatch_policies(
|
|
policies=["priority_nearest_idle", "nearest_idle"],
|
|
seed=42,
|
|
duration=120.0,
|
|
output_report=report_file,
|
|
)
|
|
|
|
assert res.scenario_type == "dispatch_policy"
|
|
assert len(res.experiments) == 2
|
|
assert res.comparison_table[0]["policy"] == "priority_nearest_idle"
|
|
assert res.comparison_table[1]["policy"] == "nearest_idle"
|
|
|
|
assert report_file.exists()
|
|
content = report_file.read_text(encoding="utf-8")
|
|
assert "Scenario Comparison: Dispatch Policy Evaluation" in content
|
|
assert "priority_nearest_idle" in content
|
|
assert "nearest_idle" in content
|