Skip to content

test: add hypothesis property-based tests for analysis invariants#42

Merged
leesaenz merged 5 commits into
mainfrom
test/hypothesis-invariants
Jul 11, 2026
Merged

test: add hypothesis property-based tests for analysis invariants#42
leesaenz merged 5 commits into
mainfrom
test/hypothesis-invariants

Conversation

@leesaenz

Copy link
Copy Markdown
Collaborator

Summary

Adds property-based invariant tests with hypothesis, per the plan in #17.

  • hypothesis>=6.0 added to the dev extra; uv.lock regenerated for CI's uv sync --locked.
  • Hypothesis profiles registered in tests/conftest.py:
    • ci (default): derandomized, 20 examples — fully deterministic in CI and locally, satisfying the reproducibility requirement without any pytest flag changes.
    • nightly: randomized, 200 examples — selected via HYPOTHESIS_PROFILE=nightly.
  • tests/test_invariants.py (7 property tests):
    • Amplitude scaling shifts integrated LUFS by exactly 20*log10(scale) (±0.1 LU).
    • Mono duplicated to stereo → correlation 1.0, width 0.0, balance 0.0, no polarity flag.
    • Polarity-flipped right channel → correlation -1.0, polarity_inverted set.
    • Time reversal preserves octave-band energies (±1 dB), spectral centroid (±2%), and stereo correlation.
    • DC offset above the 5e-4 threshold is always flagged by detect_problems.
    • Leading silence is excluded by EBU R128 gating: integrated LUFS (±0.5 LU) and true peak (±0.1 dB) unchanged.
  • .github/workflows/nightly-hypothesis.yml: daily scheduled + manual-dispatch run of the invariant tests with the randomized nightly profile (permissions: contents: read, no untrusted input interpolation).

All invariants pass on the current implementation — no bugs revealed, so no follow-up issues or xfails were needed. Tolerances were tuned empirically (time-reversal signal lengthened to 2 s to keep frame-boundary effects well below tolerance; worst observed deviation across 40 random seeds is 0.2 dB against the 1.0 dB bound).

Closes #17

Test plan

  • uv run pytest tests/test_invariants.py -q — 7 passed
  • uv run pytest tests/ -x -q — 1043 passed, 47 skipped
  • uv tool run ruff check src/ tests/ and ruff format --check — clean
  • Nightly workflow is schedule/dispatch-only; verified profile selection via HYPOTHESIS_PROFILE

🤖 Generated with Claude Code

leesaenz and others added 5 commits July 11, 2026 02:07
Property-based testing dependency for analysis invariant tests (#17).
Lockfile regenerated with uv lock for CI's --locked sync.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
New tests/test_invariants.py covering algorithmic invariants that must
hold for any valid input (issue #17):

- integrated LUFS shifts by exactly 20*log10(scale) under amplitude scaling
- identical L/R channels: correlation 1.0, width 0, balance 0, no polarity flag
- polarity-flipped right channel: correlation -1.0, polarity flag set
- time reversal preserves octave-band energies, centroid, and stereo correlation
- DC offset above threshold is always flagged by detect_problems
- leading silence is excluded by EBU R128 gating (integrated LUFS and
  true peak unchanged)

Hypothesis profiles registered in conftest.py: default "ci" profile is
derandomized for reproducibility; "nightly" (HYPOTHESIS_PROFILE=nightly)
runs randomized with 200 examples for broader coverage.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Scheduled daily run of tests/test_invariants.py with the randomized
"nightly" hypothesis profile (200 examples) for broader coverage than
the derandomized default used in CI (#17).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Match the checkout version bumped repo-wide by #39.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@leesaenz leesaenz merged commit 14b59da into main Jul 11, 2026
11 checks passed
@leesaenz leesaenz deleted the test/hypothesis-invariants branch July 11, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add property-based tests with hypothesis for analysis invariants

1 participant