"""Tests for src/pygui/backend/comparison.py."""

from pygui.backend.comparison import compare_runs


def test_identical_series():
    a = [20.0, 30.0, 40.0, 50.0, 60.0]
    result = compare_runs(a, a)
    assert result["distance"] == 0.0
    assert len(result["index_a"]) == len(a)
    assert result["index_a"] == result["index_b"]


def test_empty_series():
    result = compare_runs([], [])
    assert result["distance"] == float("inf")
    assert result["index_a"] == []
    assert result["index_b"] == []
    assert result["warping_path"] == []


def test_one_empty():
    result = compare_runs([10.0, 20.0], [])
    assert result["distance"] == float("inf")


def test_aligned_series():
    a = [10.0, 20.0, 30.0]
    b = [15.0, 25.0, 35.0]
    result = compare_runs(a, b)
    assert result["distance"] >= 0.0
    assert len(result["index_a"]) > 0
    assert len(result["index_b"]) > 0


def test_single_element():
    result = compare_runs([42.0], [42.0])
    assert result["distance"] == 0.0


def test_different_lengths():
    short = [10.0, 20.0]
    long_ = [10.0, 15.0, 20.0, 25.0, 30.0]
    result = compare_runs(short, long_)
    assert result["distance"] >= 0.0
    assert len(result["index_a"]) > 0
    assert len(result["index_b"]) > 0
    assert len(result["index_a"]) == len(result["index_b"])


def test_return_structure():
    a = [1.0, 2.0, 3.0, 4.0, 5.0]
    b = [2.0, 3.0, 4.0, 5.0, 6.0]
    result = compare_runs(a, b)
    assert "distance" in result
    assert "index_a" in result
    assert "index_b" in result
    assert "warping_path" in result
    assert isinstance(result["distance"], float)
    assert isinstance(result["index_a"], list)
    assert isinstance(result["index_b"], list)
    assert isinstance(result["warping_path"], list)
