"""
Tests for services/quality/length_checker.py
"""
import pytest

from services.quality.length_checker import check


class TestLengthCheck:
    def test_normal_length(self):
        r = check("Hello world, this is a test of translation length",
                  "Bonjour le monde, ceci est un test de longueur de traduction")
        assert r["issue"] is None
        assert r["ratio"] is not None
        assert 0.5 < r["ratio"] < 2.0

    def test_huge_translation(self):
        src = "A" * 200
        r = check(src, "x" * 1000)
        assert r["issue"] == "length_outlier"
        assert r["ratio"] > 3.5

    def test_tiny_translation(self):
        r = check("A" * 100, "ok")
        assert r["issue"] == "truncation_suspect"
        assert r["ratio"] < 0.15

    def test_empty_translation_flagged(self):
        r = check("Hello world, this is a test", "")
        assert r["issue"] == "truncation_suspect"

    def test_short_source_skips_ratio(self):
        r = check("Hi", "ok")
        assert r["issue"] is None
        assert r["ratio"] is None

    def test_empty_inputs(self):
        r = check("", "")
        assert r["issue"] is None
        assert r["source_length"] == 0
        assert r["translated_length"] == 0

    def test_none_source(self):
        r = check(None, "translation")
        assert r["issue"] is None

    def test_numeric_source(self):
        r = check("Price: 100", "100")
        assert r["issue"] is None  # numeric sources skip the check
