"""Tests para normality_tests."""

import numpy as np

from normality_tests import normality_tests


def test_normal_large_sample_is_normal():
    rng = np.random.default_rng(42)
    values = rng.normal(loc=10.0, scale=2.0, size=2000).tolist()
    result = normality_tests(values)
    assert result["n"] == 2000
    assert result["shapiro"] is not None
    assert result["jarque_bera"]["normal"] is True
    assert result["dagostino"]["normal"] is True
    assert result["is_normal"] is True


def test_skewed_sample_is_not_normal():
    rng = np.random.default_rng(7)
    values = rng.exponential(scale=1.0, size=2000).tolist()
    result = normality_tests(values)
    assert result["jarque_bera"]["normal"] is False
    assert result["dagostino"]["normal"] is False
    assert result["is_normal"] is False


def test_small_sample_returns_note():
    result = normality_tests([1, 2, 3, 4, 5])
    assert result["n"] == 5
    assert result["note"] == "muestra insuficiente"
    assert result["is_normal"] is None
    assert "jarque_bera" not in result


def test_drops_none_nan_and_non_numeric():
    rng = np.random.default_rng(1)
    base = rng.normal(0.0, 1.0, size=50).tolist()
    dirty = base + [None, float("nan"), "x", float("inf")]
    result = normality_tests(dirty)
    assert result["n"] == 50


def test_shapiro_skipped_above_5000():
    rng = np.random.default_rng(3)
    values = rng.normal(0.0, 1.0, size=6000).tolist()
    result = normality_tests(values)
    assert result["n"] == 6000
    assert result["shapiro"] is None
    # is_normal still computed from JB + D'Agostino.
    assert result["is_normal"] is True


def test_normal_below_eight_after_cleaning_is_note():
    result = normality_tests([1.0, 2.0, None, 3.0])
    assert result["n"] == 3
    assert result["note"] == "muestra insuficiente"
    assert result["is_normal"] is None
