Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Working out the expected output before you run the code 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 | |
|---|---|---|
| 1expected = 15 * 0.10 # spec: 10% discount | AThe expected output was taken from running the program rather than calculated from the specification beforehand. | |
| 2expected = discount(15) # copied from program | BThe expected value is set equal to the program's own output, so the test always passes and proves nothing. | |
| 3The specification is the source of truth: it says 3 items at $4 each must total $12, so that is the expected output. | Cexpected = 12 actual = total(3, 4) print(expected == actual) | |
| 4Work out the expected output by hand before running the code, then compare it to the actual output. | DThe expected value was copied from the program's own output, so the test proves nothing. | |
| 5actual = area(4, 5) expected = actual print(expected == actual) | Eexpected = 3 * 4 # spec says $4 each print(expected) # 12 | |
| 6# Run the program first, see it print 7 expected = 7 | FThe expected output is worked out by hand from the specification before the program is run. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
expected output — The correct result of a test case, worked out by hand from the specification before running the code. Never copy it from the program's own output, or the test proves nothing.# Spec: GST is 10% of the price
expected = 5 # 10% of 50, worked out by handexpected = 5 # worked out by hand
actual = gst(50)
print(expected == actual)# Spec: total = price * quantity
# Test: 3 items at $4 each
expected = 12# Spec: 20% off a $50 item
# By hand: 50 - 10 = 40
expected = 40expected = 12 # from the spec
actual = total(3, 4)
if actual == expected: print("PASS")