import numpy as np

from sandevistanlr import SandevistanSchedule


def test_bounds_normal() -> None:
    s = SandevistanSchedule(lr_min=1e-6, lr_max=1e-3, cycle_steps=1000, mode="normal")
    vals = s.values(2000)
    assert np.min(vals) >= s.lr_min - 1e-12
    assert np.max(vals) <= s.lr_max + 1e-12


def test_die_is_flatline() -> None:
    s = SandevistanSchedule(lr_min=1e-6, lr_max=1e-3, cycle_steps=1000, mode="die")
    vals = s.values(500)
    assert np.allclose(vals, s.lr_min)


def test_aed_has_spikes() -> None:
    s = SandevistanSchedule(
        lr_min=1e-6,
        lr_max=1e-3,
        cycle_steps=1000,
        mode="aed",
        aed_spikes=5,
        aed_spike_width=2,
    )
    vals = s.values(100)
    assert np.all((vals == s.lr_min) | (vals == s.lr_max))
    assert np.sum(vals == s.lr_max) > 0


def test_value_wraps() -> None:
    s = SandevistanSchedule(lr_min=1e-6, lr_max=1e-3, cycle_steps=10, mode="normal")
    assert s.value(0) == s.value(10)
    assert s.value(1) == s.value(11)
