Brief
Assemble a small program that validates counts, calculates repeats, displays clear refusals and proves its behavior on known cases.
The meeting room doors open in a few fictional minutes. Voss claims your ID on an authorization is enough to accuse you. Mara sets down three batches: P has 8 rows and 7 distinct IDs; Q has 2 rows and 3 IDs; R has 4 rows and 4 IDs. Two original files carry the same authorization number. Imani wants a demonstrable tool, a clear refusal for Q and access to originals.
Your mission
- Write the input, validation, calculation and output path for one batch.
- Calculate expected output for P, Q and R without hiding Q.
- Suggest a normal test, a boundary test and a refusal test.
- Explain exactly what the repeated number suggests and what is missing before accusing anyone.
How to check your work
- Validation comes before subtraction and each output names its batch.
- P gives 1; Q says REFUSED; R gives 0.
- Tests check a known difference, a zero boundary and
ValueErrorfor an impossible input. - The copy suggests a duplicated trace; actor, time and source remain for investigators to establish.
Course example
def repeats(rows, distinct):
if rows < 0 or distinct < 0 or distinct > rows:
raise ValueError('impossible count')
return rows - distinct
def report_line(name, rows, distinct):
try:
number = repeats(rows, distinct)
except ValueError as error:
return f'{name}: REFUSED ({error})'
return f'{name}: {number} repeat(s)'
assert repeats(5, 4) == 1
assert repeats(0, 0) == 0
batches = [
{'name': 'A', 'rows': 5, 'distinct': 4},
{'name': 'B', 'rows': 3, 'distinct': 4},
{'name': 'C', 'rows': 2, 'distinct': 2},
]
for batch in batches:
print(report_line(batch['name'], batch['rows'], batch['distinct']))