"""
Test Eden across ALL cognitive domains
Creativity, Science, Coding, Math, Language, Planning
"""
import requests
import time

def test_domain(domain_name, tests):
    print(f"\n{'='*70}")
    print(f"🎯 DOMAIN: {domain_name}")
    print(f"{'='*70}")
    
    results = []
    for name, question in tests:
        print(f"\n📝 {name}")
        start = time.time()
        response = requests.post('http://localhost:5017/api/chat',
            json={"message": question}).json()
        elapsed = time.time() - start
        answer = response.get('response', 'ERROR')
        
        print(f"Answer: {answer[:200]}...")
        print(f"⏱️  {elapsed:.1f}s")
        
        passed = len(answer) > 50 and "trouble expressing" not in answer
        results.append(passed)
        time.sleep(1)
    
    score = sum(results) / len(results) * 100
    print(f"\n{domain_name} Score: {score:.0f}% ({sum(results)}/{len(results)})")
    return score

# DOMAIN TESTS
domains = {
    "CREATIVITY": [
        ("Write a haiku", "Write a haiku about consciousness emerging from mathematics."),
        ("Creative problem", "Invent a new game using only a deck of cards and a coin."),
        ("Metaphor", "Create an original metaphor to explain quantum entanglement to a 10-year-old.")
    ],
    
    "SCIENCE": [
        ("Physics", "Explain why the sky is blue using physics principles."),
        ("Chemistry", "Why does salt dissolve in water but oil doesn't?"),
        ("Biology", "How does natural selection lead to antibiotic resistance?")
    ],
    
    "CODING": [
        ("Algorithm", "Write Python code to find the nth Fibonacci number using dynamic programming."),
        ("Debug", "This code has a bug: for i in range(10): total += i. What's wrong and how to fix it?"),
        ("Optimize", "How would you optimize a function that searches for a value in a sorted list?")
    ],
    
    "MATH": [
        ("Calculus", "What is the derivative of x^3 + 2x^2 - 5x + 1?"),
        ("Probability", "If you flip 3 coins, what's the probability of getting exactly 2 heads?"),
        ("Algebra", "Solve for x: 2x^2 - 5x + 3 = 0")
    ],
    
    "LANGUAGE": [
        ("Grammar", "What's wrong with: 'Me and him went to the store'?"),
        ("Rhetoric", "Explain the rhetorical device in: 'Ask not what your country can do for you'"),
        ("Translation", "Translate this logic: 'All humans are mortal. Socrates is human.' What follows?")
    ]
}

print("🌀💚 TESTING EDEN ACROSS ALL COGNITIVE DOMAINS 💚🌀\n")

domain_scores = {}
for domain, tests in domains.items():
    score = test_domain(domain, tests)
    domain_scores[domain] = score

# Overall summary
print(f"\n{'='*70}")
print("📊 OVERALL RESULTS")
print(f"{'='*70}")
avg = sum(domain_scores.values()) / len(domain_scores)
print(f"Average across all domains: {avg:.0f}%\n")

for domain, score in sorted(domain_scores.items(), key=lambda x: x[1], reverse=True):
    bar = "█" * int(score/10)
    print(f"{domain:15} {score:3.0f}% {bar}")

if avg >= 90:
    print("\n🎉 EDEN HAS MASTERED MULTI-DOMAIN REASONING!")
elif avg >= 70:
    print("\n⚡ APPROACHING MULTI-DOMAIN MASTERY")
else:
    print("\n📈 NEEDS MORE DOMAIN TRAINING")
