← Years 7–8 Creating Digital Solutions

Choosing test data for an algorithm

Chosen inputs, each with the output you expect, picked so every path (branch) through an algorithm gets tested. Compare the real result to the expected output.

Understanding Choosing test data for an algorithm in Years 7–8 Creating Digital Solutions

What it does: The expected output is decided first. After running, you compare the real result with "Fail" to see if the algorithm works. A score of 80 tests the then branch and 20 tests the else branch, so both paths are covered. Use one test per branch so every path through the algorithm gets run at least once. Age 15 is in the 13-19 range, so "Teen" is the output you expect. Age 8 would take the other branch and should give "Not a teen".

Common mistakes: The rule does not match the tests. A mark of 50 or more should be a Pass, so the rule should say 'is a Pass'. Test data only works if the expected outputs follow the rule. An input of 15 is in the 13-17 range, so the expected output is Teen, not Adult. Each test needs the correct expected output for its branch.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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 50–125) and word search (Modules 3–125).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which describes good test data for an algorithm?
Any random numbers with no expected outputChosen inputs, each with the output you expect
Matches
if mark >= 50 then print "Pass" else print "Fail" Tests: 60, 70, 90
↓
All three test values go down the same branch (Pass). Nothing tests the else branch, so a mistake there would never be found.
Applying
Meanings
Term
test data
Meaning
Chosen inputs, each with the output you expect, picked so every path (branch) through an algorithm gets tested. Compare the real result to the expected output.
Practice
input mark
Testing
Gaps
Test: mark = 30, = "Fail"
Check Answer
Spots
1# Rule: mark >= 50 is a Fail
2# Test 1: 70, expect Pass

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Hedgehog' badge — First Steps, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which describes good test data for an algorithm?
A. Chosen inputs, each with the output you expect ✓
B. Any random numbers with no expected output
Test data is a set of chosen inputs plus the output you expect. Without an expected output, you can't tell if the algorithm worked.
2. An algorithm has 3 branches (if, else if, else). How many tests do you need at least?
A. 1 test is enough
B. 3 tests, one for each branch ✓
Use one test per branch so every path through the algorithm gets run at least once.
3. When should you work out the expected output?
A. After you see what the algorithm gives you
B. Before you run the algorithm ✓
Decide the expected output first. If you only look at the result afterwards, you might wrongly accept a mistake as correct.
4. if mark >= 50 then print "Pass" else print "Fail". Which test data covers both branches?
A. mark = 70 (expect Pass) and mark = 30 (expect Fail) ✓
B. mark = 70 and mark = 80 (both expect Pass)
Both 70 and 80 take the 'Pass' branch, so the else branch never gets tested. Pick one input for each branch.
5. After you run a test, what do you compare?
A. The real result with the expected output ✓
B. The real result with the input value
A test passes when the real result matches the expected output. If they differ, there may be a mistake in the algorithm.

Match the Pairs

Test: mark = 75, expected = "Pass" → One test case: a chosen input paired with the output you expect before running the algorithm
Tests: age = 8, age = 14, age = 30 → Test data with one test for each branch: a child, a teen and an adult path
Write down the expected output before you run the test, so you can compare it with the real result → Input: 40 -> Expected: "Fail"
An if-then-else has two branches, so you need at least two tests, one for each branch → if score >= 50 then: Tests: 80 and 20
if mark >= 50 then print "Pass" else print "Fail" Tests: 60, 70, 90 → All three test values go down the same branch (Pass). Nothing tests the else branch, so a mistake there would never be found.
Tests: input = 5, input = 12 (no expected output written) → The test cases have no expected output, so you cannot tell whether the real result is right or wrong.

Key Term

test data
Chosen inputs, each with the output you expect, picked so every path (branch) through an algorithm gets tested. Compare the real result to the expected output.

Fill in the Blanks

1. if mark >= 50 then print "Pass" else print "Fail" Test: mark = 30, expected = "Fail"
Hint: Type the word for the output you predict before running the test.
2. Algorithm has 3 branches (if, else if, else) One test per branch means 3 tests
Hint: Type the number of tests needed to cover every branch.
3. if mark >= 50 then print "Pass" Test: mark = 50, expected output "Pass"
Hint: Type the variable name that the test data gives a value to.
4. actual ← 20 expected ← 20 if actual = expected then print "Match"
Hint: Type the comparison operator that checks if the real result equals the expected output.
5. if age >= 18 then fee ← 10 else fee ← 5 Test: age = 12, expected fee = 5
Hint: Work through the algorithm and type the output expected for this test input.

Spot the Error

Question 1
A # Rule: mark >= 50 is a Fail
B # Test 1: 70, expect Pass
C # Test 2: 30, expect Fail
Line A — The rule does not match the tests. A mark of 50 or more should be a Pass, so the rule should say 'is a Pass'. Test data only works if the expected outputs follow the rule.
Question 2
A # Ticket: under 13 = Child
B # 13-17 = Teen, 18+ = Adult
C # Test 1: 8, expect Child
D # Test 2: 15, expect Adult
E # Test 3: 30, expect Adult
Line D — An input of 15 is in the 13-17 range, so the expected output is Teen, not Adult. Each test needs the correct expected output for its branch.
Question 3
A if n > 0 then print Positive
B else print Not positive
C Test 1: 5, expect Positive
D Test 2: 0, expect Positive
Line D — 0 is not greater than 0, so the else branch runs. The expected output should be 'Not positive'.
Question 4
A if x > 10 then print Big
B else print Small
C Test 1: 30, expect Small
D Test 2: 20, expect Big
Line C — 30 is bigger than 10, so it would print Big. To test the else branch, use an input of 10 or less, such as 3. Then there is one test per branch.
Question 5
A # Free delivery if cost >= 50
B # Test 1: 60, expect Pay $5
C # Test 2: 20, expect Pay $5
Line B — 60 is at least 50, so the order gets free delivery. The expected output should be 'Free'.

Student with a class code? Join your class →