from log_analyzer.analyzer import analyze_logs


def test_analyze_logs_basic():
    entries = [
        {"level": "ERROR", "source": "auth", "message": "login failed"},
        {"level": "INFO", "source": "auth", "message": "login succeeded"},
        {"level": "ERROR", "source": "db", "message": "connection timeout"},
    ]
    result = analyze_logs(entries)
    assert "frequencies" in result
    assert "anomalies" in result
    assert len(result["anomalies"]) > 0


def test_analyze_large_batch():
    """Realistic batch — this is the one that uses too much memory."""
    sources = [f"service-{i}" for i in range(50)]
    levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
    entries = []
    for i in range(10_000):
        entries.append(
            {
                "level": levels[(i // len(sources)) % len(levels)],
                "source": sources[i % len(sources)],
                "message": f"Event {i}: something happened in the system",
            }
        )
    result = analyze_logs(entries)
    assert len(result["frequencies"]) == len(sources) * len(levels)
    assert len(result["anomalies"]) > 0
