Use this skill when verifying that code behaves correctly, especially for DSP emulation, binary parsing, and audio processing.
Verification Approaches
Invariant Checking
- Identify invariants: conditions that must always hold.
- Assert invariants at boundaries (function entry/exit, state transitions).
- Examples: buffer length matches expected size, sample values are in valid range, array indices are in bounds.
Edge Case Analysis
For any function, systematically check:
- Empty input (zero-length arrays, null, undefined).
- Boundary values (0, 1, max, min, off-by-one).
- Invalid input (malformed data, out-of-range values).
- Overflow/underflow (integer overflow in sample calculations, buffer overrun).
- Concurrency (AudioWorklet runs on a separate thread — shared state races).
Reference Comparison
For DSP emulation:
- Compare output against known-good reference implementations (bsnes/higan, blargg's SPC_DSP).