Skip to content

fix: add minimum input length guards to all test modules - #34

Merged
stevenang merged 1 commit into
masterfrom
fix/input-length-guards
Apr 5, 2026
Merged

stevenang merged 1 commit into
masterfrom
fix/input-length-guards

Conversation

@stevenang

Copy link
Copy Markdown
Owner

Summary

  • Matrix.py: replace silent (-1.0, False) with descriptive error tuple when input < 1024 bits
  • Complexity.py: replace silent (-1.0, False) with descriptive error tuple when input < 2×block_size
  • Spectral.py: add guard for n < 1000 (NIST SP 800-22 minimum)
  • TemplateMatching.non_overlapping_test: add guard for n < block×pattern_size to prevent division by zero when block_size=0
  • TemplateMatching.overlapping_patterns: add guard for n < block_size to prevent division by zero in xObs computation
  • RandomExcursions.random_excursions_test: add guard for num_cycles=0 to prevent division by zero

All error returns follow the existing (0.0, False, 'Error: ...') pattern already established by RunTest.longest_one_block_test and Universal.statistical_test.

Related Issues

Closes #13
Related to #10 (users getting confusing results with short inputs)

Test plan

  • Run python3 test_e.py and confirm all results are unchanged (1,000,000 bit input well above all minimums)
  • Test each guarded function with a short input and confirm the error tuple is returned instead of a crash or -1.0

🤖 Generated with Claude Code

Addresses issue #13. Tests that received short inputs either crashed
(division by zero, IndexError) or silently returned the magic value
-1.0, giving users no indication of why the test failed.

Changes per file:
- Matrix.py: replace (-1.0, False) with descriptive error tuple
- Complexity.py: replace (-1.0, False) with descriptive error tuple
- Spectral.py: add n < 1000 guard (NIST SP 800-22 minimum)
- TemplateMatching.non_overlapping_test: add guard for n < block*pattern_size
  to prevent division by zero when block_size=0
- TemplateMatching.overlapping_patterns: add guard for n < block_size
  to prevent division by zero at xObs computation
- RandomExcursions.random_excursions_test: add guard for num_cycles=0
  to prevent division by zero in xObs = sum(.../ inner_term)

All error returns follow the existing (0.0, False, 'Error: ...') pattern
established by RunTest.longest_one_block_test and Universal.statistical_test.

Closes #13

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@stevenang
stevenang merged commit dd8f926 into master Apr 5, 2026
1 check passed
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.

About data input size

1 participant