Skip to content

Latest commit

 

History

History
373 lines (285 loc) · 9 KB

File metadata and controls

373 lines (285 loc) · 9 KB

CONSIM Testing Framework

Comprehensive testing suite for the Multiversal Consciousness Framework

Overview

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

Quick Start

Running Tests

# 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)

Using pytest (if installed)

# 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 report

Test Structure

tests/
├── __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

Test Coverage

Unit Tests (test_lattice.py)

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

Integration Tests (test_integration.py)

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

Server Tests (test_server.py)

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

Demo Server Tests (test_demo.py)

TestDemoServer - 5 tests

  • Lattice initialization
  • Update mechanics
  • Node addition
  • Quantum collapse
  • State serialization

Test Results Summary

Total Tests: 63
├── Unit Tests: 24
├── Integration Tests: 14
├── Server Tests: 20
└── Demo Tests: 5

Status: ✅ All tests passing
Execution Time: ~6.5 seconds

Writing New Tests

Unit Test Example

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)

Integration Test Example

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)

Test Best Practices

1. Test Organization

  • 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

2. Test Independence

  • Each test should be independent
  • Don't rely on test execution order
  • Clean up resources in tearDown()
  • Use fresh instances for each test

3. Assertions

  • Use specific assertion methods (assertEqual, assertGreater, etc.)
  • Include helpful assertion messages
  • Test both success and failure cases
  • Verify edge cases and boundary conditions

4. Performance

  • Keep unit tests fast (< 0.1s each)
  • Mark slow tests appropriately
  • Use smaller grid sizes for testing (32-64 nodes)
  • Profile performance-critical tests

Continuous Integration

GitHub Actions (Example)

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 all

Code Coverage

To 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.html

Troubleshooting

Import Errors

If you encounter import errors:

# Ensure PYTHONPATH includes src/
export PYTHONPATH="${PYTHONPATH}:$(pwd)/src"

Missing Dependencies

Install test dependencies:

pip install -r requirements.txt
pip install httpx pytest pytest-cov

WebSocket Test Errors

The "(1000, None)" errors in WebSocket tests are expected - they indicate normal WebSocket closure.

Slow Tests

To run only fast tests:

python run_tests.py fast

Performance Benchmarks

Expected performance metrics:

Configuration Nodes Target FPS Memory
Demo 32 30+ < 50MB
Standard 64 30+ ~100MB
Production 128 20+ ~200MB
Maximum 256+ 15+ ~400MB

Testing Checklist

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

Mathematical Verification

The test suite verifies key mathematical properties:

Core EQ Implementation

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

Multiverse Superposition

M(t) = Σ[i=1→3] λᵢ(t) Uᵢ
  • ✅ Dirichlet sampling: Σλᵢ = 1
  • ✅ Universe-specific frequency modulation
  • ✅ Weighted consciousness aggregation

Future Enhancements

Potential testing improvements:

  1. Fuzz Testing - Random input generation to find edge cases
  2. Load Testing - Stress testing with 1000+ nodes
  3. Visual Regression - Screenshot comparison for frontend
  4. Property-Based Testing - Hypothesis-style testing
  5. Mutation Testing - Verify test quality with mutation analysis

Contributing

When contributing tests:

  1. Follow the existing test structure
  2. Maintain or improve code coverage
  3. Add docstrings to test methods
  4. Update this documentation
  5. Ensure all tests pass before submitting PR

Resources


Last Updated: 2025-11-14 Test Framework Version: 1.0.0 Total Tests: 63 (all passing ✅)