Skip to content

Commit

Permalink
[topgen] Fix types in test_runs() code
Browse files Browse the repository at this point in the history
The existing code wasn't quite right: I think it actually misused the
all() function. (Thank you, mypy, for noticing!)

For each group of runs (indexed by j), they get binned by length into
n_runs and then we check that each bin has an acceptable size. The new
version of the code returns False (failure!) if any bin is out of
bounds and returns True if we survived to the end.

Signed-off-by: Rupert Swarbrick <[email protected]>
  • Loading branch information
rswarbrick committed Jul 13, 2023
1 parent d440d94 commit 3b92a31
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions util/topgen/strong_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ def test_runs(self):
for i in range(n_seq + 1):
seq_start.append(i * self.SEQ_SIZE_BYTES)

results = []

for j in range(n_seq):
n_runs = [[0 for i in range(6)] for j in range(2)]

Expand Down Expand Up @@ -134,14 +132,14 @@ def test_runs(self):
i += 1
# The runs test passes only if all numbers of runs are within
# specified limits
result = (all(n_runs[0][k] >= self.RUNS_LOW_THRESHOLD[k]) and
all(n_runs[1][k] >= self.RUNS_LOW_THRESHOLD[k]) and
all(n_runs[0][k] <= self.RUNS_HIGH_THRESHOLD[k]) and
all(n_runs[1][k] <= self.RUNS_HIGH_THRESHOLD[k])
for k in range(6))

results.append(result)
return all(results)
for k in range(6):
lo = self.RUNS_LOW_THRESHOLD[k]
hi = self.RUNS_HIGH_THRESHOLD[k]
if not (lo <= n_runs[0][k] <= hi and
lo <= n_runs[1][k] <= hi):
return False

return True

def test_long_run(self):
""" Perform Runs test on buffered data
Expand Down

0 comments on commit 3b92a31

Please sign in to comment.