← ACARA Digital Technologies Years 9–10

Working out the expected output before you run the code

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.

Understanding Working out the expected output before you run the code in ACARA Digital Technologies Years 9–10

What it does: The expected output comes from the spec's rule, calculated by hand as 3 x 4 = 12, before running the program. If you decide the expected output after seeing the result, you can be tricked into accepting a wrong answer. The spec says what the program SHOULD do. The program only shows what it DOES do, and that may contain bugs. The correct average is (10 + 20) / 2 = 15. Copying 18 makes the test pass, but the bug is still there. A hand calculation is independent of the code. Copying the output only repeats whatever the code does, even when it is wrong.

Common mistakes: The expected value was calculated with the program's own formula, so the test can never fail. Work it out by hand from the spec: 4 * 3 = 12, so it should be expected = 12. The expected output must be worked out by hand (10% of 20 is 2.0 or 20 * 0.10), not taken from the function being tested. Using discount(20) just compares the function with itself.

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 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.

Learning
Duo
A spec says: 'Add 10% GST to the price.' For a price of $50, how should you get the expected output?
Calculate 50 x 1.10 = 55 by hand from the spec before running the codeRun the program and write down whatever number it prints
Matches
actual = area(4, 5) expected = actual print(expected == actual)
↓
The expected value is set equal to the program's own output, so the test always passes and proves nothing.
Applying
Meanings
Term
expected output
Meaning
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.
Practice
def discount(total):
Testing
Gaps
= 5 # 10% of 50, worked out by hand
Check Answer
Spots
2price, qty = 4, 3
3expected = price * qty

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

The 'Galaxy Phoenix' badge — Orbit Champion, 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. A spec says: 'Add 10% GST to the price.' For a price of $50, how should you get the expected output?
A. Run the program and write down whatever number it prints
B. Calculate 50 x 1.10 = 55 by hand from the spec before running the code ✓
The expected output comes from the specification and your own calculation. The program's output is only the actual output you compare it to.
2. When should you work out the expected output of a test case?
A. Before you run the code ✓
B. After you see what the program prints
If you decide the expected output after seeing the result, you can be tricked into accepting a wrong answer.
3. Which is the source of truth for what a program should do?
A. The problem specification ✓
B. The program's own output
The spec says what the program SHOULD do. The program only shows what it DOES do, and that may contain bugs.
4. Mia's program has a bug and prints 18 for the average of 10 and 20. She copies 18 into the Expected column. What does this show?
A. The test proves nothing because the bug is now hidden inside the expected output ✓
B. The test passes, so the program is correct
The correct average is (10 + 20) / 2 = 15. Copying 18 makes the test pass, but the bug is still there.
5. A spec says: 'Students get a pass if their mark is 50 or more.' What is the expected output for a mark of 50?
A. Fail, because the program printed Fail
B. Pass, because the spec says 50 or more ✓
Read the spec to decide the answer. 50 meets the 'or more' rule, so it must be Pass, whatever the program prints.

Match the Pairs

expected = 15 * 0.10 # spec: 10% discount → The expected output is worked out by hand from the specification before the program is run.
expected = discount(15) # copied from program → The expected value was copied from the program's own output, so the test proves nothing.
The specification is the source of truth: it says 3 items at $4 each must total $12, so that is the expected output. → expected = 3 * 4 # spec says $4 each print(expected) # 12
Work out the expected output by hand before running the code, then compare it to the actual output. → expected = 12 actual = total(3, 4) print(expected == actual)
actual = area(4, 5) expected = actual print(expected == actual) → The expected value is set equal to the program's own output, so the test always passes and proves nothing.
# Run the program first, see it print 7 expected = 7 → The expected output was taken from running the program rather than calculated from the specification beforehand.

Key Term

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.

Fill in the Blanks

1. # Spec: GST is 10% of the price expected = 5 # 10% of 50, worked out by hand
Hint: Type the variable name that stores the correct result you worked out by hand.
2. expected = 5 # worked out by hand actual = gst(50) print(expected == actual)
Hint: Type the comparison operator that checks whether two values are equal.
3. # Spec: total = price * quantity # Test: 3 items at $4 each expected = 12
Hint: Type the total you calculate by hand from the spec, before running any code.
4. # Spec: 20% off a $50 item # By hand: 50 - 10 = 40 expected = 40
Hint: Type the final price from the hand calculation shown in the comment.
5. expected = 12 # from the spec actual = total(3, 4) if actual == expected: print("PASS")
Hint: Type the keyword that starts a decision comparing the actual and expected results.

Spot the Error

Question 1
A # Spec: cost = price * qty
B price, qty = 4, 3
C expected = price * qty
D actual = price * qty
E print(expected == actual)
Line C — The expected value was calculated with the program's own formula, so the test can never fail. Work it out by hand from the spec: 4 * 3 = 12, so it should be expected = 12.
Question 2
A expected = discount(20)
B actual = discount(20)
C if expected == actual:
D print('PASS')
Line A — The expected output must be worked out by hand (10% of 20 is 2.0 or 20 * 0.10), not taken from the function being tested. Using discount(20) just compares the function with itself.
Question 3
A # Spec: area = width * height
B def area(w, h):
C return w * h
D expected = 3 + 4
E print(area(3, 4) == expected)
Line D — The hand calculation does not follow the spec. The spec says area = width * height, so the expected value is 3 * 4 = 12, not 3 + 4 = 7.
Question 4
A # Spec: tax is 10% of income
B expected = 500 * 0.01
C actual = tax(500)
D print(expected, actual)
Line B — The spec says tax is 10%, which is 0.10. Using 0.01 gives the wrong expected output (5.0 instead of 50.0), so the test would wrongly fail correct code.
Question 5
A # Spec: 15% off if over 100
B price = 120
C expected = 120 * 0.15
D actual = final(price)
E print(expected == actual)
Line C — The hand calculation gives the discount amount, not the final price. A 15% discount means the customer pays 85%, so expected = 120 * 0.85 = 102.

Student with a class code? Join your class →