"""Tests for cross-framework parity validator."""

from __future__ import annotations

import numpy as np

from model_osmosis.format.parity import compare_tensor_maps


def test_compare_tensor_maps_float_tolerance_passes():
    ref = {"w": np.array([1.0, 2.0, 3.0], dtype=np.float32)}
    out = {"w": np.array([1.0, 2.0, 3.0 + 1e-7], dtype=np.float32)}
    result = compare_tensor_maps(ref, out)
    assert result.passed is True
    assert result.checked_tensors == 1


def test_compare_tensor_maps_integer_requires_exact():
    ref = {"ids": np.array([1, 2, 3], dtype=np.int64)}
    out = {"ids": np.array([1, 4, 3], dtype=np.int64)}
    result = compare_tensor_maps(ref, out)
    assert result.passed is False
    assert "ids" in result.failing_tensors
    assert "ids" in result.checksum_mismatches


def test_compare_tensor_maps_marks_missing_and_unexpected():
    ref = {"a": np.array([1.0], dtype=np.float32)}
    out = {"b": np.array([1.0], dtype=np.float32)}
    result = compare_tensor_maps(ref, out)
    assert result.passed is False
    assert "missing:a" in result.failing_tensors
    assert "unexpected:b" in result.failing_tensors

