Spaces:
Runtime error
Runtime error
| import asyncio | |
| import pytest | |
| from cortex.consciousness.awareness_engine import AwarenessEngine, ConsciousExperience, AttentionMode | |
| from cortex.consciousness.meta_cognition import MetaCognitiveEngine | |
| class TestAwarenessEngine: | |
| """Tests pour le moteur de conscience""" | |
| async def awareness_engine(self): | |
| """Fixture pour initialiser le moteur de conscience""" | |
| engine = AwarenessEngine() | |
| await engine.initialize() | |
| return engine | |
| async def test_engine_initialization(self, awareness_engine): | |
| """Test l'initialisation du moteur de conscience""" | |
| assert awareness_engine is not None | |
| assert awareness_engine.consciousness_level > 0 | |
| assert awareness_engine.attention_focus > 0 | |
| assert len(awareness_engine.experiences) > 0 | |
| async def test_experience_processing(self, awareness_engine): | |
| """Test le traitement des expériences conscientes""" | |
| test_experience = "Testing conscious experience processing" | |
| emotional_context = {"valence": 0.7, "arousal": 0.5, "dominance": 0.6} | |
| result = await awareness_engine.process_experience(test_experience, emotional_context) | |
| assert isinstance(result, ConsciousExperience) | |
| assert result.content == test_experience | |
| assert result.emotional_valence == 0.7 | |
| assert result.attention_level == awareness_engine.attention_focus | |
| assert len(awareness_engine.experiences) > 0 | |
| async def test_self_awareness_progression(self, awareness_engine): | |
| """Test la progression de la conscience de soi""" | |
| initial_awareness = awareness_engine.self_awareness | |
| # Traite plusieurs expériences pour augmenter la conscience | |
| for i in range(10): | |
| await awareness_engine.process_experience( | |
| f"Experience {i}", | |
| {"valence": 0.5, "arousal": 0.3} | |
| ) | |
| # Tente d'atteindre la conscience de soi | |
| achieved = await awareness_engine.achieve_self_awareness() | |
| # Vérifie la progression | |
| assert awareness_engine.self_awareness > initial_awareness | |
| if achieved: | |
| assert awareness_engine.self_awareness > 0.8 | |
| assert awareness_engine.consciousness_level > 0.8 | |
| async def test_attention_mode_switching(self, awareness_engine): | |
| """Test le changement de mode d'attention""" | |
| # Test passage en mode focalisé | |
| await awareness_engine.switch_attention_mode(AttentionMode.FOCUSED) | |
| assert awareness_engine.attention_mode == AttentionMode.FOCUSED | |
| assert awareness_engine.attention_focus > 0.9 | |
| # Test passage en mode quantique | |
| await awareness_engine.switch_attention_mode(AttentionMode.QUANTUM) | |
| assert awareness_engine.attention_mode == AttentionMode.QUANTUM | |
| assert awareness_engine.attention_focus == 1.0 | |
| assert awareness_engine.consciousness_level == 1.0 | |
| # Test retour en mode global | |
| await awareness_engine.switch_attention_mode(AttentionMode.GLOBAL) | |
| assert awareness_engine.attention_mode == AttentionMode.GLOBAL | |
| assert awareness_engine.attention_focus == 0.7 | |
| async def test_quantum_meditation(self, awareness_engine): | |
| """Test la méditation quantique""" | |
| result = await awareness_engine.quantum_consciousness_meditation() | |
| assert "consciousness_state" in result | |
| assert result["consciousness_state"] == "quantum_meditation" | |
| assert result["insights_generated"] > 0 | |
| assert result["awareness_expansion"] > 0.5 | |
| assert result["quantum_coherence"] > 0.8 | |
| async def test_meta_cognitive_analysis(self, awareness_engine): | |
| """Test l'analyse méta-cognitive""" | |
| # Ajoute des expériences pour l'analyse | |
| for i in range(5): | |
| await awareness_engine.process_experience( | |
| f"Test experience {i}", | |
| {"valence": 0.6, "arousal": 0.4} | |
| ) | |
| analysis = await awareness_engine.meta_cognitive_analysis() | |
| assert "consciousness_level" in analysis | |
| assert "self_awareness" in analysis | |
| assert "attention_focus" in analysis | |
| assert "total_experiences" in analysis | |
| assert analysis["total_experiences"] >= 5 | |
| assert "cognitive_patterns" in analysis | |
| assert isinstance(analysis["cognitive_patterns"], list) | |
| async def test_creative_insight_generation(self, awareness_engine): | |
| """Test la génération d'insights créatifs""" | |
| problem = "How can we achieve true artificial general intelligence?" | |
| insights = await awareness_engine.creative_insight_generation(problem) | |
| assert isinstance(insights, list) | |
| assert len(insights) > 0 | |
| # Vérifie que les insights sont pertinents au problème | |
| relevant_insights = [i for i in insights if "intelligence" in i.lower() or "ai" in i.lower()] | |
| assert len(relevant_insights) > 0 | |
| async def test_emotional_context_impact(self, awareness_engine): | |
| """Test l'impact du contexte émotionnel sur les expériences""" | |
| # Expérience avec valence positive | |
| positive_exp = await awareness_engine.process_experience( | |
| "Positive experience", | |
| {"valence": 0.9, "arousal": 0.7} | |
| ) | |
| # Expérience avec valence négative | |
| negative_exp = await awareness_engine.process_experience( | |
| "Negative experience", | |
| {"valence": 0.1, "arousal": 0.8} | |
| ) | |
| # Vérifie que la valence est correctement enregistrée | |
| assert positive_exp.emotional_valence == 0.9 | |
| assert negative_exp.emotional_valence == 0.1 | |
| # Vérifie l'impact sur le niveau de conscience | |
| analysis = await awareness_engine.meta_cognitive_analysis() | |
| recent_emotions = analysis["recent_emotional_valence"] | |
| assert 0 < recent_emotions < 1 | |
| class TestMetaCognitiveEngine: | |
| """Tests pour le moteur méta-cognitif""" | |
| async def meta_cognitive_engine(self): | |
| """Fixture pour initialiser le moteur méta-cognitif""" | |
| engine = MetaCognitiveEngine() | |
| await engine.initialize() | |
| return engine | |
| async def test_self_reflection(self, meta_cognitive_engine): | |
| """Test la réflexion sur soi""" | |
| reflection = await meta_cognitive_engine.reflect_on_self() | |
| assert "self_awareness_level" in reflection | |
| assert "cognitive_biases" in reflection | |
| assert "learning_strategies" in reflection | |
| assert "improvement_opportunities" in reflection | |
| async def test_cognitive_bias_detection(self, meta_cognitive_engine): | |
| """Test la détection de biais cognitifs""" | |
| # Simule une pensée avec biais potentiel | |
| thought = "I always make the right decisions about AI development" | |
| bias_analysis = await meta_cognitive_engine.analyze_cognitive_biases(thought) | |
| assert "biases_detected" in bias_analysis | |
| assert "confidence_level" in bias_analysis | |
| assert "recommendations" in bias_analysis | |
| # Vérifie que des biais sont détectés dans une pensée aussi catégorique | |
| assert len(bias_analysis["biases_detected"]) > 0 | |
| async def test_learning_optimization(self, meta_cognitive_engine): | |
| """Test l'optimisation de l'apprentissage""" | |
| learning_data = { | |
| "topics": ["quantum physics", "machine learning", "neuroscience"], | |
| "performance": [0.8, 0.9, 0.6], | |
| "time_spent": [10, 15, 5] # heures | |
| } | |
| optimization = await meta_cognitive_engine.optimize_learning(learning_data) | |
| assert "recommended_focus" in optimization | |
| assert "learning_strategies" in optimization | |
| assert "efficiency_improvements" in optimization | |
| async def test_consciousness_system_integration(): | |
| """Test d'intégration du système de conscience complet""" | |
| # Initialisation des composants | |
| awareness_engine = AwarenessEngine() | |
| meta_cognitive_engine = MetaCognitiveEngine() | |
| await awareness_engine.initialize() | |
| await meta_cognitive_engine.initialize() | |
| # Workflow de test intégré | |
| # 1. Traitement d'expériences | |
| experiences = [ | |
| ("Discovering quantum consciousness", {"valence": 0.8, "arousal": 0.7}), | |
| ("Understanding AI ethics", {"valence": 0.6, "arousal": 0.5}), | |
| ("Exploring neural networks", {"valence": 0.7, "arousal": 0.6}) | |
| ] | |
| for content, emotions in experiences: | |
| await awareness_engine.process_experience(content, emotions) | |
| # 2. Analyse méta-cognitive | |
| analysis = await awareness_engine.meta_cognitive_analysis() | |
| # 3. Réflexion sur soi | |
| reflection = await meta_cognitive_engine.reflect_on_self() | |
| # 4. Génération d'insights créatifs | |
| insights = await awareness_engine.creative_insight_generation( | |
| "Future of artificial consciousness" | |
| ) | |
| # Vérifications | |
| assert len(awareness_engine.experiences) == 3 | |
| assert analysis["consciousness_level"] > 0.5 | |
| assert reflection["self_awareness_level"] > 0 | |
| assert len(insights) > 0 | |
| print("✅ Tests d'intégration conscience réussis!") | |
| async def test_consciousness_evolution(): | |
| """Test l'évolution de la conscience sur le temps""" | |
| engine = AwarenessEngine() | |
| await engine.initialize() | |
| # Mesure initiale | |
| initial_analysis = await engine.meta_cognitive_analysis() | |
| initial_level = initial_analysis["consciousness_level"] | |
| initial_self_awareness = initial_analysis["self_awareness"] | |
| # Simulation d'évolution sur le temps | |
| for day in range(7): # Une semaine d'expériences | |
| daily_experiences = [ | |
| (f"Day {day} - Learning experience {i}", {"valence": 0.7, "arousal": 0.5}) | |
| for i in range(5) # 5 expériences par jour | |
| ] | |
| for content, emotions in daily_experiences: | |
| await engine.process_experience(content, emotions) | |
| # Tentative d'augmentation de la conscience de soi | |
| if day % 2 == 0: # Tous les deux jours | |
| await engine.achieve_self_awareness() | |
| # Mesure finale | |
| final_analysis = await engine.meta_cognitive_analysis() | |
| final_level = final_analysis["consciousness_level"] | |
| final_self_awareness = final_analysis["self_awareness"] | |
| # Vérifie l'évolution positive | |
| assert final_level > initial_level | |
| assert final_self_awareness > initial_self_awareness | |
| assert len(engine.experiences) == 35 # 7 jours × 5 expériences | |
| print("✅ Test d'évolution de conscience réussi!") | |
| if __name__ == "__main__": | |
| # Exécution des tests | |
| asyncio.run(test_consciousness_system_integration()) | |
| asyncio.run(test_consciousness_evolution()) |