Comprehensive testing suite for the Multiversal Consciousness Framework
This testing framework provides complete coverage of the CONSIM consciousness simulation system, including:
- Unit Tests: Individual component testing (nodes, universes, lattice engine)
- Integration Tests: System-level interactions and workflows
- Server Tests: API endpoints and WebSocket functionality
- Performance Tests: Benchmarking and scalability testing
# Run all tests
python run_tests.py
# Run specific test suites
python run_tests.py unit # Unit tests only
python run_tests.py integration # Integration tests only
python run_tests.py server # Server tests only
python run_tests.py performance # Performance benchmarks
python run_tests.py fast # Quick tests (skip performance)# Install pytest
pip install pytest pytest-cov
# Run tests with pytest
pytest # All tests
pytest tests/test_lattice.py # Specific file
pytest -v # Verbose output
pytest --cov=src # With coverage reporttests/
├── __init__.py # Test initialization and path setup
├── test_lattice.py # Unit tests for lattice engine
├── test_server.py # Integration tests for FastAPI server
├── test_demo.py # Tests for demo server
└── test_integration.py # End-to-end integration tests
TestConsciousnessNode - 9 tests
- Node initialization and properties
- Core EQ consciousness calculation: C = A(x) * Φ(x) * e^(iτ(x))
- Phase evolution over time
- Attention density calculation (Gaussian field)
- Physics updates (velocity, position, friction)
- Boundary conditions and quantum tunneling
- Intelligence tensor systems
- Node serialization
TestUniverse - 3 tests
- Universe initialization with λ coefficients
- Node containment detection
- Universe serialization
TestConsciousnessLattice - 14 tests
- Lattice initialization
- Dirichlet sampling for λ weights
- Attention field normalization (∫A(x)dμ(x) = 1)
- Lattice update mechanics
- Global consciousness integral calculation
- Dynamic node addition/removal
- Quantum collapse effects
- Cluster detection
- Parameter updates
- State transmission
TestUniverseMode - 1 test
- Visualization mode enumeration
TestSystemIntegration - 7 tests
- Multi-node interactions
- Cluster formation
- Universe-node interactions
- Attention field conservation
- Consciousness continuity
- Parameter effects
- System stability over 100+ updates
TestPerformanceBenchmarks - 3 tests
- Update performance (60 FPS target)
- Node scaling (32, 64, 128 nodes)
- Memory usage profiling
TestEdgeCases - 4 tests
- Empty lattice behavior
- Single node system
- Extreme parameter values
- Rapid node addition/removal
TestServerAPI - 10 tests
- GET /api/status - System status
- GET /api/stats - Global statistics
- GET /api/parameters - Current parameters
- POST /api/parameters - Update parameters
- POST /api/nodes - Create nodes
- POST /api/collapse - Quantum collapse
- POST /api/mode/{mode} - Set visualization mode
- POST /api/reset - Reset simulation
- GET /api/export - Export state
- Invalid mode handling
TestServerWebSocket - 6 tests
- WebSocket connection and initial state
- Adding nodes via WebSocket
- Parameter updates via WebSocket
- Mouse influence messaging
- Quantum collapse events
- Mode changes
TestServerModels - 4 tests
- ParameterUpdate Pydantic model
- NodeCreate model validation
- MouseInfluence model
- QuantumCollapse model
TestDemoServer - 5 tests
- Lattice initialization
- Update mechanics
- Node addition
- Quantum collapse
- State serialization
Total Tests: 63
├── Unit Tests: 24
├── Integration Tests: 14
├── Server Tests: 20
└── Demo Tests: 5
Status: ✅ All tests passing
Execution Time: ~6.5 seconds
import unittest
from lattice import ConsciousnessNode
class TestNewFeature(unittest.TestCase):
def setUp(self):
"""Set up test fixtures."""
self.node = ConsciousnessNode(x=0.0, y=0.0)
def test_new_functionality(self):
"""Test description."""
# Arrange
expected_value = 42.0
# Act
result = self.node.some_new_method()
# Assert
self.assertEqual(result, expected_value)def test_complex_workflow(self):
"""Test complete workflow."""
lattice = ConsciousnessLattice(grid_size=32)
# Add nodes
node1 = lattice.add_node(0.0, 0.0)
node2 = lattice.add_node(50.0, 50.0)
# Run simulation
for _ in range(10):
lattice.update(0.016)
# Verify results
self.assertGreater(len(lattice.clusters), 0)- One test class per component/feature
- Descriptive test names that explain what's being tested
- Use setUp() for common test fixtures
- Group related tests together
- Each test should be independent
- Don't rely on test execution order
- Clean up resources in tearDown()
- Use fresh instances for each test
- Use specific assertion methods (assertEqual, assertGreater, etc.)
- Include helpful assertion messages
- Test both success and failure cases
- Verify edge cases and boundary conditions
- Keep unit tests fast (< 0.1s each)
- Mark slow tests appropriately
- Use smaller grid sizes for testing (32-64 nodes)
- Profile performance-critical tests
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest pytest-cov httpx
- name: Run tests
run: python run_tests.py allTo generate code coverage reports:
# Install pytest-cov
pip install pytest-cov
# Run with coverage
pytest --cov=src --cov-report=html --cov-report=term
# View HTML report
open htmlcov/index.htmlIf you encounter import errors:
# Ensure PYTHONPATH includes src/
export PYTHONPATH="${PYTHONPATH}:$(pwd)/src"Install test dependencies:
pip install -r requirements.txt
pip install httpx pytest pytest-covThe "(1000, None)" errors in WebSocket tests are expected - they indicate normal WebSocket closure.
To run only fast tests:
python run_tests.py fastExpected performance metrics:
| Configuration | Nodes | Target FPS | Memory |
|---|---|---|---|
| Demo | 32 | 30+ | < 50MB |
| Standard | 64 | 30+ | ~100MB |
| Production | 128 | 20+ | ~200MB |
| Maximum | 256+ | 15+ | ~400MB |
Before committing code:
- All existing tests pass
- New features have unit tests
- Integration tests updated if needed
- No performance regressions
- Code coverage maintained or improved
- Documentation updated
The test suite verifies key mathematical properties:
C(t) = ∫[M_C] A(x,t) Φ(x,t) e^(iτ(x,t)) dμ(x)
- ✅ Complex consciousness calculation
- ✅ Phase evolution: τ(t+dt) = τ(t) + Φ×dt×2π
- ✅ Attention normalization: ∫A(x)dμ(x) = 1
M(t) = Σ[i=1→3] λᵢ(t) Uᵢ
- ✅ Dirichlet sampling: Σλᵢ = 1
- ✅ Universe-specific frequency modulation
- ✅ Weighted consciousness aggregation
Potential testing improvements:
- Fuzz Testing - Random input generation to find edge cases
- Load Testing - Stress testing with 1000+ nodes
- Visual Regression - Screenshot comparison for frontend
- Property-Based Testing - Hypothesis-style testing
- Mutation Testing - Verify test quality with mutation analysis
When contributing tests:
- Follow the existing test structure
- Maintain or improve code coverage
- Add docstrings to test methods
- Update this documentation
- Ensure all tests pass before submitting PR
Last Updated: 2025-11-14 Test Framework Version: 1.0.0 Total Tests: 63 (all passing ✅)