Test‐Driven Design - treytomes/redstone_sim GitHub Wiki

Test-Driven Design Document: Redstone Circuit Simulator

1. Unit Tests for Components

1.1 Redstone Wire Tests

  • Power Level Transmission: Verify wire transmits exact power level from source
  • Signal Decay: Confirm power decreases by 1 per block traversed
  • Maximum Length: Test that signal terminates after 15 blocks without amplification
  • Multiple Inputs: Verify wire carries highest power level when receiving multiple inputs
  • Connection Patterns: Test all possible connection configurations (straight, corners, T-junctions, crossings)

1.2 Power Source Tests

  • Button Functionality:
    • Verify button generates correct power level (15)
    • Confirm button deactivates after configured duration
    • Test button reactivation after use
  • Switch/Lever Tests:
    • Verify switch toggles between on/off states
    • Confirm switch maintains state between simulation cycles
    • Test power output level consistency

1.3 Redstone Torch Tests

  • Power Generation: Verify unpowered torch outputs power level 15
  • Inversion Logic: Confirm torch turns off when its attachment block is powered
  • Burnout Mechanics: Test torch temporarily deactivates after rapid toggling
  • Recovery: Verify torch recovers from burnout after appropriate delay
  • Attachment Configurations: Test all valid torch placement positions

1.4 Repeater Tests

  • Signal Restoration: Verify repeater restores any input signal to level 15
  • Delay Accuracy: Test each delay setting (1-4 ticks) functions correctly
  • Directional Behavior: Confirm signal passes only in forward direction
  • Lock Functionality: Verify repeater locks when side input is powered
  • Power Requirements: Test minimum power level required for activation

1.5 Transistor Tests

  • Basic Functionality: Verify output signal passes only when control input is powered
  • Signal Strength: Test output strength matches input strength when active
  • Logic Modes: Confirm each logic mode (AND/OR/XOR) functions correctly
  • Response Time: Verify activation/deactivation timing is consistent

2. Integration Tests

2.1 Signal Propagation Tests

  • Multi-Component Paths: Test signal correctly traverses through multiple component types
  • Branch Behavior: Verify signal branches properly at junctions
  • Complex Routing: Test signal routing through complex component arrangements
  • Timing Consistency: Verify signals propagate with consistent timing across identical paths

2.2 Circuit Pattern Tests

  • Clock Circuits: Test various redstone clock designs function correctly
  • Logic Gates: Verify AND, OR, NOT, XOR, NAND, NOR gates work as expected
  • Memory Cells: Test RS-NOR latches and other memory elements maintain state
  • Pulse Circuits: Verify pulse limiters, extenders, and one-shot circuits function correctly

2.3 Edge Case Tests

  • High Density Circuits: Test performance with densely packed components
  • Update Order: Verify component update sequence matches expected behavior
  • Signal Race Conditions: Test circuits with timing-sensitive behavior
  • Loop Handling: Verify circuits with feedback loops function correctly

3. System Tests

3.1 Grid Environment Tests

  • Grid Boundaries: Test behavior at grid edges
  • Component Placement: Verify rules for valid/invalid component placement
  • Grid Scaling: Test performance with various grid sizes

3.2 Simulation Control Tests

  • Real-time Operation: Verify continuous simulation runs at correct speed
  • Step Mode: Test single-tick advancement functions correctly
  • Speed Control: Verify simulation speed adjustments work as expected
  • Pause/Resume: Test simulation state is preserved when paused

3.3 UI Functionality Tests

  • Component Selection: Verify all components can be selected and placed
  • Editing Operations: Test copy, paste, delete, rotate functions
  • Selection Tools: Verify area selection tools function correctly
  • View Controls: Test pan, zoom, and navigation controls

4. Persistence Tests

4.1 Save/Load Tests

  • Circuit Preservation: Verify all component properties are saved and restored
  • State Persistence: Test that powered states are correctly preserved
  • File Format Integrity: Verify resistance to file corruption
  • Backward Compatibility: Test loading circuits from previous versions

4.2 Export/Import Tests

  • Image Export: Verify circuit diagrams are generated correctly
  • Circuit Sharing: Test sharing mechanisms function properly

5. Performance Tests

5.1 Load Testing

  • Large Circuit Performance: Measure update rate with circuits of increasing size
  • Component Density: Test performance with varying component densities
  • Memory Usage: Monitor memory consumption during extended operation

5.2 Stress Tests

  • Rapid Input Changes: Test behavior with rapidly changing input signals
  • Maximum Components: Verify stability with maximum supported component count
  • Long-Duration Simulation: Test stability over extended operation periods

6. Regression Test Suite

  • Component Interaction Matrix: Systematic tests of all possible component interactions
  • Known Circuit Designs: Library of reference circuits with expected behaviors
  • Bug Reproduction Cases: Tests that verify specific bug fixes remain resolved

7. User Acceptance Tests

  • Tutorial Completion: Verify users can complete guided tutorial tasks
  • Circuit Construction: Test users can build basic functional circuits
  • Tool Usability: Measure time required to perform common operations
  • Learning Curve: Assess new user ability to understand simulation behavior

Each test should include specific inputs, expected outputs, and acceptance criteria to ensure consistent evaluation of simulator functionality.