import json
from pathlib import Path

from klt51_core import Klt51Engine, Reper4, d_star, lambda_truth


def test_lambda_truth():
    result = lambda_truth(0.9, 0.6, 0.4, 0.7)
    assert result.status == "ok"
    assert result.lambda_value is not None
    assert result.delta is not None
    assert result.auth is not None


def test_d_star():
    assert d_star(0.9, 0.6, 0.4) is not None


def test_engine_demo():
    demo = Path(__file__).resolve().parents[2] / "examples" / "demo_project.json"
    data = json.loads(demo.read_text(encoding="utf-8"))
    result = Klt51Engine().analyze(data)
    assert result["pix_count"] >= 10
    assert result["defect_count"] >= 1
    assert 0 <= result["cri"] <= 1
