Skip to content

Commit

Permalink
test: attempt to fix the chisquare calculation error
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros11 committed Jan 28, 2025
1 parent af710eb commit 4ef41e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/instruments/test_qrng.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def extract(n):
return qrng


def normalized_chisquare(x, y):
"""Normalize frequency sums to avoid errors."""
return chisquare(x, np.sum(x) * y / np.sum(y))


def test_random_chisquare(qrng):
data = qrng.random(1000)

Expand All @@ -32,5 +37,5 @@ def test_random_chisquare(qrng):

expected_frequency = len(data) / nbins
expected_frequencies = np.full(nbins, expected_frequency)
_, p_value = chisquare(observed_frequencies, expected_frequencies)
_, p_value = normalized_chisquare(observed_frequencies, expected_frequencies)
assert p_value > P_VALUE_CUTOFF

0 comments on commit 4ef41e5

Please sign in to comment.