"""Tests for EvidenceAnalyzer._extract_score and ConstraintEvidence dataclass."""

from unittest.mock import MagicMock

from local_deep_research.advanced_search_system.constraint_checking.evidence_analyzer import (
    ConstraintEvidence,
    EvidenceAnalyzer,
)


class TestExtractScore:
    def setup_method(self):
        mock_model = MagicMock()
        self.analyzer = EvidenceAnalyzer(model=mock_model)

    def test_valid_decimal_score(self):
        result = self.analyzer._extract_score("POSITIVE: 0.8", "POSITIVE")
        assert result == 0.8

    def test_bracketed_score(self):
        result = self.analyzer._extract_score("POSITIVE: [0.75]", "POSITIVE")
        assert result == 0.75

    def test_no_match_returns_default(self):
        result = self.analyzer._extract_score("no score here", "POSITIVE")
        assert result == 0.1

    def test_integer_score(self):
        result = self.analyzer._extract_score("POSITIVE: 1", "POSITIVE")
        assert result == 1.0

    def test_case_insensitive(self):
        result = self.analyzer._extract_score("positive: 0.6", "POSITIVE")
        assert result == 0.6

    def test_different_label(self):
        result = self.analyzer._extract_score(
            "NEGATIVE: 0.3\nPOSITIVE: 0.7", "NEGATIVE"
        )
        assert result == 0.3

    def test_uncertainty_label(self):
        result = self.analyzer._extract_score(
            "UNCERTAINTY: [0.2]", "UNCERTAINTY"
        )
        assert result == 0.2


class TestConstraintEvidenceDataclass:
    def test_creation(self):
        evidence = ConstraintEvidence(
            positive_confidence=0.7,
            negative_confidence=0.2,
            uncertainty=0.1,
            evidence_text="some text",
            source="search",
        )
        assert evidence.positive_confidence == 0.7
        assert evidence.negative_confidence == 0.2
        assert evidence.uncertainty == 0.1
        assert evidence.evidence_text == "some text"
        assert evidence.source == "search"
