Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Test coverage of branches and loops 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 | |
|---|---|---|
| 1if mark >= 50: print("Pass") else: print("Fail") | AThe loop was only tested running many times. It was never tested running zero times (count = 0) or once (count = 1), so edge bugs could be missed. | |
| 2for item in cart: total += item | BTest the loop with an empty list (zero times), a one-item list (once) and a longer list (many times). | |
| 3Every branch of an if/elif/else needs its own test value, so three branches need at least three tests. | Cif score >= 80: grade = "A" elif score >= 50: grade = "B" else: grade = "C" | |
| 4A loop that never runs when given an empty list shows the zero-times case, and any code inside it stays untested. | DOnly age 20 was tested, so the else branch never ran. The Minor line is untested code. Add a test such as age 10. | |
| 5# Tests run: age = 20 only if age >= 18: print("Adult") else: print("Minor") | ENeeds at least two tests for full branch coverage: one mark that is 50 or more and one that is below 50. | |
| 6# Tests run: count = 5 only while count > 0: count -= 1 | Ffor n in []: print(n) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
test coverage — Testing so that every if/elif/else branch runs at least once and every loop is tried running zero times, once and many times. Any code never run is untested.if mark >= 50:
print("Pass")
else:items = []
for x in items:
print(x)count = 0
for i in range(1):
count += 1for n in [2, 4, 6]:
total += n
print(total)if age < 13:
print("Child")
elif age < 20: