Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Testing that invalid input is rejected worksheet is part of the ACARA Digital Technologies Years 9–10 — Testing and Validating Programs journey. Print it as a booklet?
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1assert not is_valid(-5) | Atry: check_age(-5) print("FAIL") except ValueError: print("PASS") | |
| 2except ValueError: print("PASS") | Bassert not is_valid(-5) | |
| 3To test that a validator rejects a bad value, call it with that value and assert it returns False | CPasses only if is_valid(-5) returns False, so the bad value -5 is correctly rejected | |
| 4If bad input should raise an error, put the call in a try block and print PASS in the except block | DThere is no FAIL message after the call in try. If no error occurs, the test never reports a failure, so a broken validator would go unnoticed. | |
| 5assert is_valid(-5) | EThis asserts that the bad value is accepted. It should be assert not is_valid(-5), so the test passes only when -5 is rejected. | |
| 6try: check_age(-5) except ValueError: print("PASS") | FRuns when the bad input raises a ValueError, which is the expected error, so the test passes |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
assert not is_valid(-5) — Tests that bad input is rejected: call the validator with an invalid value and assert it returns False. If an error is expected, use try/except; no error means the test fails.assert not is_valid(-5)assert not is_valid(-5)try:
register(-5)
except ValueError:assert validate(-5) == Falsetry:
register(-5)
except ValueError: