"""Sequence playback loop flag coercion."""

import os
import sys

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

from util.sequence_playback import (  # noqa: E402
    _coerce_loop,
    _ordered_unique_preset_ids_in_lane,
)


def test_coerce_loop():
    assert _coerce_loop({"loop": True}) is True
    assert _coerce_loop({"loop": False}) is False
    assert _coerce_loop({"sequence_loop": 0}) is False
    assert _coerce_loop({}) is True


def test_ordered_unique_preset_ids_in_lane():
    lane = [
        {"preset_id": "6", "beats": 1},
        {"preset_id": "4", "beats": 2},
        {"preset_id": "6", "beats": 1},
    ]
    assert _ordered_unique_preset_ids_in_lane(lane) == ["6", "4"]
