Skip to content

Conversation

Copy link

Copilot AI commented Oct 31, 2025

Extends Pattern Analyzer's statistical testing capabilities with five new plugins for detecting non-randomness in binary data.

New Plugins

  • Chi-Square Test (chi_square) - Byte distribution uniformity via chi-square goodness-of-fit (255 DoF). Batch + streaming.
  • Kolmogorov-Smirnov Test (kolmogorov_smirnov) - CDF-based non-parametric uniformity test. Batch only.
  • Gap Test (gap) - Bit pattern occurrence spacing via geometric distribution model. Configurable patterns with automatic bin merging.
  • Poker Test (poker) - Fixed-width bit segment pattern distribution (2^m patterns). Configurable hand size (2-8 bits). Batch + streaming.
  • Permutation Test (permutation) - Byte block ordering analysis (k! permutations). Lehmer code indexing for efficiency. Configurable block size (2-5 bytes).

Implementation

All plugins:

  • Inherit from TestPlugin base class
  • Return TestResult with p-values bounded to [0.0, 1.0]
  • Handle edge cases (empty data, insufficient samples)
  • Use proper statistical distributions (gamma, Kolmogorov, geometric)
  • Support alpha parameter for significance level

Streaming implementations (Chi-Square, Poker) use stateful accumulators with update()/finalize() pattern.

Usage

from patternanalyzer.plugins.chi_square import ChiSquareTest
from patternanalyzer.plugin_api import BytesView

test = ChiSquareTest()
data = BytesView(b'\x00' * 1000)
result = test.run(data, {"alpha": 0.01})

print(f"Test: {result.test_name}, Passed: {result.passed}, P-value: {result.p_value}")
# Output: Test: chi_square, Passed: False, P-value: 0.0

Testing

112 comprehensive test cases covering:

  • Batch/streaming equivalence and state management
  • Uniform/biased distributions and edge cases
  • Parameter validation and boundary conditions
  • Large datasets (100KB-800KB) for performance validation
  • Statistical properties (degrees of freedom, distribution checks)
  • Metadata validation (category, p_values dict, metrics completeness)

All tests pass successfully.

Original prompt

Yeni test türleri(plugin) ekle. Projenin yapısına uygun plsun.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 31, 2025 18:05
Co-authored-by: EdgeTypE <34396598+EdgeTypE@users.noreply.github.com>
…ue bounds check

Co-authored-by: EdgeTypE <34396598+EdgeTypE@users.noreply.github.com>
Copilot AI changed the title [WIP] Add new test types as plugins Add five statistical test plugins for binary randomness analysis Oct 31, 2025
Copilot AI requested a review from EdgeTypE October 31, 2025 18:17
@EdgeTypE
Copy link
Owner

@copilot Add more test.

Co-authored-by: EdgeTypE <34396598+EdgeTypE@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 31, 2025

@copilot Add more test.

Added 45 new tests, bringing the total from 67 to 112 tests (+67% increase).

New tests cover:

  • Edge cases (empty data, single byte, extreme values)
  • Large datasets (100KB-800KB)
  • Streaming validation (chunk handling, state resets)
  • Statistical properties (DoF calculations, distribution checks)
  • Metadata validation (category, p_values, metrics)
  • Performance with very large data

All 112 tests pass. Commit: 81b3d9b

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.

2 participants