import numpy as np
import pytest

from m3m_twin.srf import parse_response_csv, summarize_response


def test_triangular_response_summary():
    wavelength = np.array([500.0, 510.0, 520.0, 530.0, 540.0])
    response = np.array([0.0, 0.5, 1.0, 0.5, 0.0])
    summary = summarize_response(wavelength, response)
    assert summary["effectiveWavelengthNm"] == pytest.approx(520.0)
    assert summary["fwhmNm"] == pytest.approx(20.0)


def test_response_csv_rejects_unsorted_wavelengths():
    payload = b"wavelength,response\n500,0.1\n490,1.0\n510,0.1\n"
    with pytest.raises(ValueError):
        parse_response_csv(payload)

