Test coverage of branches and loops
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.
Understanding Test coverage of branches and loops in ACARA Digital Technologies Years 9–10
What it does: This code has three branches (if, elif, else). Test scores such as 90, 60 and 20 make each branch run once, giving full branch coverage. Looping over an empty list runs the loop body zero times. This is one of the three loop cases that must be tested, and the print line is never run.
Common mistakes: An if statement must end with a colon, so this line should be 'if n > 0:'. Once it is fixed, full branch coverage needs tests such as 5, -3 and 0 so every branch runs. A total must start at 0. With an empty list the loop runs zero times, so the program would print 1 instead of 0. It should be 'total = 0'. This is why testing the zero-times case matters.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 536–590) and word search (Modules 536–622).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
test coverageFill in the Blanks
Spot the Error
Student with a class code? Join your class →