from __future__ import annotations
import importlib.util
from pathlib import Path
import numpy as np

MODULE_PATH = Path(__file__).resolve().parents[1] / "tools/plot_sr_diagnostics.py"
spec = importlib.util.spec_from_file_location("plot_sr_diagnostics", MODULE_PATH)
module = importlib.util.module_from_spec(spec); assert spec.loader; spec.loader.exec_module(module)


def test_circular_lag_recovers_roll():
    reference = np.array([0.0, 1.0, 0.0, -1.0, 0.2])
    signal = np.roll(reference, 2)
    assert module.circular_lag(reference, signal) == -2


def test_generalization_includes_all_training_conditions():
    repo = Path(__file__).resolve().parents[3]
    points = module.generalization_points(repo)
    training = [p for p in points if p["classification"] == "training"]
    assert {p["scene"] for p in training} == set(module.TRAINING_SCENES)
    assert len(training) == 7
