Spaces:
Runtime error
Runtime error
| import torch | |
| import numpy as np | |
| import pytest | |
| from singularity_core import SingularityCore | |
| class TestSingularityCore: | |
| """Тесты сингулярного ядра самозаворачивания.""" | |
| def setup_method(self): | |
| """Инициализация для каждого теста.""" | |
| self.singularity = SingularityCore( | |
| singularity_radius=0.01, | |
| wormhole_depth=2.1, | |
| rotation_speed=0.0, | |
| embedding_dim=256 | |
| ) | |
| # Создаем тестовое состояние | |
| self.test_state = torch.randn(1, 10, 256) | |
| def test_singularity_initialization(self): | |
| """Тест инициализации сингулярного ядра.""" | |
| assert self.singularity.singularity_radius == 0.01 | |
| assert self.singularity.wormhole_depth == 2.1 | |
| assert self.singularity.rotation_speed == 0.0 | |
| assert self.singularity.embedding_dim == 256 | |
| assert self.singularity.singularity_cycles == 0 | |
| def test_singularity_transform(self): | |
| """Тест сингулярной трансформации.""" | |
| original_state = self.test_state.clone() | |
| transformed_state = self.singularity.compute_singularity_transform(original_state, cycle=1) | |
| # Проверяем, что состояние действительно изменилось | |
| state_diff = torch.norm(transformed_state - original_state) | |
| assert state_diff > 0, "Сингулярная трансформация должна изменять состояние" | |
| # Проверяем размерности | |
| assert transformed_state.shape == original_state.shape | |
| def test_self_wrapping_cycle(self): | |
| """Тест полного цикла самозаворачивания.""" | |
| result = self.singularity.self_wrapping_cycle(self.test_state, "Тестовый ввод") | |
| # Проверяем успешность операции | |
| assert result["success"] == True | |
| assert result["cycle"] == 1 | |
| # Проверяем метрики | |
| metrics = result["metrics"] | |
| assert "state_transformation" in metrics | |
| assert "curvature" in metrics | |
| assert "entropy" in metrics | |
| assert "coherence" in metrics | |
| # Проверяем, что трансформация произошла | |
| assert metrics["state_transformation"] > 0 | |
| def test_parameter_update(self): | |
| """Тест обновления параметров сингулярности.""" | |
| original_radius = self.singularity.singularity_radius | |
| original_depth = self.singularity.wormhole_depth | |
| self.singularity.update_parameters( | |
| singularity_radius=0.05, | |
| wormhole_depth=2.5 | |
| ) | |
| assert self.singularity.singularity_radius == 0.05 | |
| assert self.singularity.wormhole_depth == 2.5 | |
| assert self.singularity.singularity_radius != original_radius | |
| assert self.singularity.wormhole_depth != original_depth | |
| def test_singularity_state(self): | |
| """Тест получения состояния сингулярности.""" | |
| state = self.singularity.get_singularity_state() | |
| assert "singularity_radius" in state | |
| assert "wormhole_depth" in state | |
| assert "rotation_speed" in state | |
| assert "cycles" in state | |
| assert "current_state_shape" in state | |
| assert "transformation_history_length" in state | |
| def test_multiple_cycles(self): | |
| """Тест множественных циклов самозаворачивания.""" | |
| # Первый цикл | |
| result1 = self.singularity.self_wrapping_cycle(self.test_state, "Цикл 1") | |
| cycle1 = result1["cycle"] | |
| # Второй цикл | |
| result2 = self.singularity.self_wrapping_cycle(self.test_state, "Цикл 2") | |
| cycle2 = result2["cycle"] | |
| # Проверяем, что циклы увеличиваются | |
| assert cycle2 > cycle1 | |
| assert cycle2 == cycle1 + 1 | |
| # Проверяем историю трансформаций | |
| assert len(self.singularity.transformation_history) == 2 | |
| def test_wormhole_effect(self): | |
| """Тест wormhole эффекта.""" | |
| # Создаем состояние с известными значениями | |
| test_state = torch.ones(1, 10, 256) | |
| # Применяем трансформацию с разными циклами | |
| transformed1 = self.singularity.compute_singularity_transform(test_state, cycle=1) | |
| transformed2 = self.singularity.compute_singularity_transform(test_state, cycle=2) | |
| # Проверяем, что результаты разные для разных циклов | |
| diff = torch.norm(transformed1 - transformed2) | |
| assert diff > 0, "Wormhole эффект должен давать разные результаты для разных циклов" | |
| def test_curvature_calculation(self): | |
| """Тест вычисления кривизны.""" | |
| original_state = self.test_state.clone() | |
| transformed_state = self.singularity.compute_singularity_transform(original_state) | |
| metrics = self.singularity._compute_transformation_metrics(original_state, transformed_state) | |
| # Проверяем, что кривизна вычисляется корректно | |
| assert metrics["curvature"] >= 0 | |
| assert not np.isnan(metrics["curvature"]) | |
| assert not np.isinf(metrics["curvature"]) | |
| def test_entropy_calculation(self): | |
| """Тест вычисления энтропии.""" | |
| original_state = self.test_state.clone() | |
| transformed_state = self.singularity.compute_singularity_transform(original_state) | |
| metrics = self.singularity._compute_transformation_metrics(original_state, transformed_state) | |
| # Проверяем, что энтропия вычисляется корректно | |
| assert metrics["entropy"] >= 0 | |
| assert not np.isnan(metrics["entropy"]) | |
| assert not np.isinf(metrics["entropy"]) | |
| def test_coherence_calculation(self): | |
| """Тест вычисления когерентности.""" | |
| original_state = self.test_state.clone() | |
| transformed_state = self.singularity.compute_singularity_transform(original_state) | |
| metrics = self.singularity._compute_transformation_metrics(original_state, transformed_state) | |
| # Проверяем, что когерентность в разумных пределах | |
| assert 0 <= metrics["coherence"] <= 1 | |
| assert not np.isnan(metrics["coherence"]) | |
| def test_singularity_response_generation(self): | |
| """Тест генерации ответа сингулярности.""" | |
| metrics = { | |
| "state_transformation": 0.15, | |
| "curvature": 0.6, | |
| "entropy": 2.5, | |
| "coherence": 0.8 | |
| } | |
| response = self.singularity._generate_singularity_response(metrics, "Тестовый ввод") | |
| # Проверяем, что ответ содержит ожидаемые элементы | |
| assert "Сингулярность активирована" in response | |
| assert "Высокая кривизна" in response | |
| assert "Информационная энтропия" in response | |
| assert "Когерентность сингулярности" in response | |
| assert "Тестовый ввод" in response | |
| if __name__ == "__main__": | |
| # Запуск тестов | |
| pytest.main([__file__, "-v"]) |