"""Tests for Bosch column-name structure parsing."""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "03_bosch"))

import structure  # noqa: E402


def test_parse_feature_column():
    p = structure.parse_column("L3_S36_F3939")
    assert p == {"line": 3, "station": 36, "kind": "F", "idx": 3939}


def test_parse_date_column():
    p = structure.parse_column("L0_S0_D1")
    assert p["kind"] == "D" and p["line"] == 0 and p["station"] == 0


def test_non_structural_columns_return_none():
    assert structure.parse_column("Id") is None
    assert structure.parse_column("Response") is None


def test_group_by_station_preserves_order():
    cols = ["Id", "L0_S0_F0", "L0_S0_F2", "L1_S24_F1", "Response"]
    groups = structure.group_by_station(cols)
    assert groups == {"L0_S0": ["L0_S0_F0", "L0_S0_F2"], "L1_S24": ["L1_S24_F1"]}


def test_sort_is_numeric_not_lexical():
    keys = ["L0_S10", "L0_S9", "L1_S0"]
    assert structure.sort_station_keys(keys) == ["L0_S9", "L0_S10", "L1_S0"]
