import pytest
from krrkt.engine.scorer import calculate_score, score_color, count_words

class TestCountWords:
    def test_simple_russian(self):
        assert count_words("Мы выпускаем подшипники") == 3

    def test_empty(self):
        assert count_words("") == 0

    def test_mixed_languages(self):
        assert count_words("Claude Code is great инструмент") == 5

    def test_with_punctuation(self):
        assert count_words("Привет, мир! Как дела?") == 4

    def test_hyphenated(self):
        assert count_words("Санкт-Петербург красив") == 2

class TestCalculateScore:
    def test_clean_text_no_findings(self):
        score = calculate_score("Выпускаем подшипники каждый день", [])
        assert score == 10

    def test_empty_text(self):
        assert calculate_score("", []) == 0

    def test_heavily_polluted(self):
        findings = [{"weight": 100}, {"weight": 100}, {"weight": 100}]
        score = calculate_score("Один два три четыре", findings)
        assert score < 2

    def test_half_polluted(self):
        findings = [{"weight": 100}, {"weight": 100}]
        score = calculate_score("Один два три четыре", findings)
        assert score == 1.2

    def test_weight_zero_no_effect(self):
        findings_zero = [{"weight": 0}]
        findings_hundred = [{"weight": 100}]
        text = "Один два три четыре пять"
        assert calculate_score(text, findings_zero) > calculate_score(text, findings_hundred)

    def test_weight_50_counts_half(self):
        findings = [{"weight": 50}]
        text = "Один два три четыре пять"
        assert calculate_score(text, findings) == 7.2

    def test_score_clamped_to_0(self):
        findings = [{"weight": 100}] * 20
        assert calculate_score("Одно слово", findings) >= 0

    def test_score_integer_display(self):
        score = calculate_score("Выпускаем подшипники каждый день", [])
        assert score == 10

class TestScoreColor:
    def test_green(self):
        assert score_color(7.5) == "green"
        assert score_color(10) == "green"

    def test_orange(self):
        assert score_color(5) == "orange"
        assert score_color(7.4) == "orange"

    def test_red(self):
        assert score_color(4.9) == "red"
        assert score_color(0) == "red"
