"""LED strip reverse (n5) mapping for upside-down installs."""

import os
import sys

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DRIVER_SRC = os.path.join(PROJECT_ROOT, "led-driver", "src")
if DRIVER_SRC not in sys.path:
    sys.path.insert(0, DRIVER_SRC)

from patterns.pattern_direction import is_reversed, led_i, signed  # noqa: E402
from preset import Preset  # noqa: E402


class _FakeDriver:
    num_leds = 10


def test_preset_reverse_sets_n5():
    p = Preset({"p": "chase", "reverse": True})
    assert p.n5 == 1
    assert is_reversed(p) is True


def test_led_i_mirrors_index():
    drv = _FakeDriver()
    p = Preset({"p": "chase", "n5": 1})
    assert led_i(drv, p, 0) == 9
    assert led_i(drv, p, 9) == 0
    assert led_i(drv, p, 3) == 6


def test_signed_negates_when_reversed():
    p = Preset({"p": "chase", "n5": 1})
    assert signed(p, 4) == -4
    assert signed(Preset({"p": "chase", "n5": 0}), 4) == 4
