from __future__ import annotations

import mlx.core as mx
import pytest

import mlx_signal as ms


def test_asarray_returns_mlx_array() -> None:
    x = ms.asarray([1, 2, 3])
    assert x.shape == (3,)
    assert x.dtype == mx.float32


def test_normalize_peak_scales_signal() -> None:
    x = ms.asarray([0.0, 2.0, -1.0])
    y = ms.normalize_peak(x)
    assert y.dtype == mx.float32
    assert float(mx.max(mx.abs(y)).item()) == pytest.approx(1.0)


def test_frame_splits_signal() -> None:
    x = ms.asarray([0, 1, 2, 3, 4], dtype=mx.float32)
    frames = ms.frame(x, frame_length=3, hop_length=1)
    assert frames.shape == (3, 3)


def test_frame_validates_shape() -> None:
    with pytest.raises(ValueError):
        ms.frame(ms.asarray([[1, 2], [3, 4]]), frame_length=2, hop_length=1)
