import pytest

from m3m_twin.envelope import (
    minimum_altitude_for_speed_m,
    mission_envelope,
    trigger_limited_max_speed_m_s,
)


def test_sixty_metre_trigger_limit_exceeds_five_metres_per_second():
    assert trigger_limited_max_speed_m_s(60, 80) == pytest.approx(5.375115, abs=1e-6)


def test_minimum_altitude_for_five_metres_per_second_at_eighty_percent_overlap():
    assert minimum_altitude_for_speed_m(5, 80) == pytest.approx(55.812757, abs=1e-6)


def test_low_altitude_scenario_is_speed_clamped():
    rows = mission_envelope(altitudes_m=(30,), front_overlaps_pct=(80,))
    assert rows[0]["speedClampedByCadence"] is True
    assert rows[0]["actualPlannedSpeedMS"] < 5


def test_default_envelope_has_thirty_five_scenarios():
    rows = mission_envelope()
    assert len(rows) == 35
    assert all(row["expectedImageFileCount"] == row["captureEventCount"] * 5 for row in rows)

