Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This What it means to validate an algorithm or program 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 average([2, 4, 6]) == 4 | AThis only checks the input data. It does not prove the program produces the correct output for the problem. | |
| 2if age >= 0 and age <= 120: | BRunning without errors is not proof of correctness. The output must be checked against expected results from test cases. | |
| 3A program can run with no errors and still be wrong, so you must compare its output with the expected output | Cdef total(a, b): return a * b print(total(2, 3)) # expected 5, got 6 | |
| 4A program is only as validated as its tests: passing every test in a weak set proves little | DValidates one case: checks the function gives the expected output of 4 for this test input | |
| 5print('No errors, so the program is valid!') | Etests = [(0, 0)] for x, want in tests: print(double(x) == want) | |
| 6if int(age) > 0: # validates my program | FValidates input data, not the program: it checks the value is sensible before it is used |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
validate a program — To prove a program gives the correct output for its problem by running or tracing it against test cases. Running without errors is not proof; it is only as validated as its tests.def double(n):
return n * 2
print(double(4) == 8)if actual == expected:
print("PASS")
else: print("FAIL")def double(n):
return n * 2
assert double(3) == 6tests = [(2, 4), (5, 10)]
for n, want in tests:
print(double(n) == want)tests = [(2, 4), (5, 10), (0, 0)]
print(len(tests), "test cases")