from GramAddict.core.darwin_engine import DarwinEngine
from GramAddict.core.growth_brain import GrowthBrain
from GramAddict.core.resonance_engine import ResonanceEngine


class TestCognitiveEdgeCases:
    # Resonance Engine
    def test_resonance_edge_cases(self):
        engine = ResonanceEngine(my_username="test_user")

        # 1. Empty strings shouldn't crash
        assert engine.calculate_resonance({"description": "", "username": ""}) == 0.5

        # 2. Very long descriptions
        long_str = "word " * 10000
        res = engine.calculate_resonance({"description": long_str})
        assert isinstance(res, float)

        # 3. None values
        score = engine.calculate_resonance({"description": None})
        assert score == 0.5

    # Darwin Engine
    def test_darwin_edge_cases(self):
        engine = DarwinEngine("test_user")

        # 1. synthesize interaction with 0.0
        prof = engine.synthesize_interaction_profile(0.0)
        assert prof["initial_dwell_sec"] > 0

        # 2. Negative resonance (should default upwards or bound)
        prof_neg = engine.synthesize_interaction_profile(-10.0)
        assert prof_neg["initial_dwell_sec"] > 0

        # 3. Extreme resonance
        prof_max = engine.synthesize_interaction_profile(10.0)  # > 1.0
        assert prof_max["initial_dwell_sec"] > 0

    def test_growth_brain_edge_cases(self):
        engine = GrowthBrain(username="test")

        # 1. Call circadian without history
        engine.session_history = []
        pacing = engine.get_circadian_pacing()
        assert 0.4 <= pacing <= 1.2

        # 2. Call with extreme limits
        engine.session_history = [{"boredom_peak": 100.0, "time": "unknown"}] * 100
        pacing2 = engine.get_circadian_pacing()
        assert pacing2 > 0.0

        # 3. Evaluate persona drift with empty outcomes
        engine.refine_persona([])
        # Shouldn't crash
