← QCE Digital Solutions Unit 1

Judging what code does from runtime input and output evidence

Running unfamiliar code with chosen inputs and recording the outputs to infer what it does without reading the source. The evidence only covers the inputs you tried.

Understanding Judging what code does from runtime input and output evidence in QCE Digital Solutions Unit 1

What it does: An input-output table is how black-box evidence is recorded. The pairs 2 to 8 and 3 to 27 suggest the code cubes its input. The inference matches the evidence, but a good tester states what was not covered. Untested inputs could behave differently. Black-box testing builds evidence from real runs. A name alone is not evidence of behaviour. The pattern suggests squaring, but the evidence only covers the inputs you tried. Test zero, negatives and decimals before claiming more. Choose inputs that could break your current theory. Repeating a tested input adds no new information. Black-box testing looks only at inputs and outputs. The inner workings stay hidden, so you infer the process.

Common mistakes: Each test must run mystery() on one input at a time. Passing the whole list tests mixes every input together. It should be mystery(x) so each input has its own output. The table should map each input to its output. Here the key and value are swapped, so the evidence is recorded backwards. It should be results[x] = out.

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 158–380) and word search (Modules 82–380).

Take this worksheet further — free with Cloodit

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

Learning
Duo
You are given a function you cannot read. Which first step best matches black-box testing?
Guess what it does from its name and trust that guessRun it with chosen inputs and record each output in a table
Matches
mystery(2) -> 4 so mystery always doubles its input
↓
One test result is used to claim a rule that holds for all inputs. Squaring also gives 4 from 2, so more varied inputs are needed.
Applying
Meanings
Term
black-box testing
Meaning
Running unfamiliar code with chosen inputs and recording the outputs to infer what it does without reading the source. The evidence only covers the inputs you tried.
Practice
def mystery(n):
Testing
Gaps
x in [0, 1, 5, -2]:
Check Answer
Spots
2for x in tests:
3 print(x, mystery(tests))

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

The 'Walrus' badge — Method Master, 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. You are given a function you cannot read. Which first step best matches black-box testing?
A. Guess what it does from its name and trust that guess
B. Run it with chosen inputs and record each output in a table ✓
Black-box testing builds evidence from real runs. A name alone is not evidence of behaviour.
2. Which set of test inputs is more informative for an unknown function that takes a number?
A. -5, 0, 1, 10, 100 ✓
B. 4, 4, 4, 4, 4
A varied set (negative, zero, small, large) shows how the output changes. Repeating the same input only gives one piece of evidence.
3. You run unknown code with inputs 2, 3 and 4 and get outputs 4, 9 and 16. What can you reasonably infer?
A. It probably squares the input, but you should test more values to be sure ✓
B. It definitely squares every possible input, so no more testing is needed
The pattern suggests squaring, but the evidence only covers the inputs you tried. Test zero, negatives and decimals before claiming more.
4. Which is the best way to record evidence from black-box testing?
A. A paragraph describing the code you think is inside
B. An input-output table with one row per test run ✓
A table pairs each input with its actual output so you can spot the pattern and others can check it.
5. Your tests of an unknown function only used inputs from 1 to 10. Which statement is correct?
A. You cannot say how it behaves for 0, negative numbers or very large numbers ✓
B. You know how it behaves for every number because the pattern held
Stating the limits of the evidence is part of black-box testing. Untested inputs remain unknown.

Match the Pairs

mystery(4) -> 16, mystery(5) -> 25, mystery(-3) -> 9 → An input-output table: the outputs are each input squared, so the process is probably n * n.
mystery(0), mystery(-1), mystery(1000) → Informative inputs: a zero, a negative and a large value that test edge cases and reveal the limits of the behaviour.
Record each chosen input and the output it produced in a table, so you can look for a pattern. → | input | output | | 2 | 8 | | 3 | 27 |
Infer the process from the pattern, but state the limit: you only know the inputs you tried. → # 3 tests fit n * 2, but I did not test negatives
mystery(2) -> 4 so mystery always doubles its input → One test result is used to claim a rule that holds for all inputs. Squaring also gives 4 from 2, so more varied inputs are needed.
Tried mystery(1), mystery(2), mystery(3): it is fully tested and correct for every number → Three small positive inputs are claimed to prove behaviour for every number. The evidence only covers the inputs tried, so zero, negatives and large values are untested.

Key Term

black-box testing
Running unfamiliar code with chosen inputs and recording the outputs to infer what it does without reading the source. The evidence only covers the inputs you tried.

Fill in the Blanks

1. for x in [0, 1, 5, -2]: print(x, mystery(x))
Hint: Type the keyword that repeats the block once for each chosen test input.
2. result = mystery(x) print(x, "->", result)
Hint: Type the function that shows the input and output pair on screen as evidence.
3. table = {} result = mystery(x) table[x] = result
Hint: Type the variable name that holds the output being recorded in the input-output table.
4. if mystery(3) == 9 and mystery(5) == 25: print("Looks like squaring")
Hint: Type the logical operator that needs both observed results to match before inferring the process.
5. tested = [1, 2, 5, 10] if 0 not in tested: print("Limit: 0 never tested")
Hint: Type the operator that checks a value is absent from the tested inputs, showing a limit of the evidence.

Spot the Error

Question 1
A tests = [0, 1, 5, -3]
B for x in tests:
C print(x, mystery(tests))
Line C — Each test must run mystery() on one input at a time. Passing the whole list tests mixes every input together. It should be mystery(x) so each input has its own output.
Question 2
A results = {}
B for x in [0, 1, 5, -3]:
C out = mystery(x)
D results[out] = x
E print(results)
Line D — The table should map each input to its output. Here the key and value are swapped, so the evidence is recorded backwards. It should be results[x] = out.
Question 3
A x = int(input('Enter: '))
B y = mystery(x)
C print('In:', y, 'Out:', x)
Line C — The labels are attached to the wrong values. The input x is shown as Out and the result y as In, which gives misleading evidence. It should be print('In:', x, 'Out:', y).
Question 4
A # Black-box test of mystery()
B for n in [3, 3, 3, 3]:
C print(n, mystery(n))
D # Table shows: out is n + 2
Line B — Repeating the same input gives no new information, so you cannot infer a pattern. Informative inputs vary: zero, a small number, a larger number and a negative, such as [0, 1, 5, -2].
Question 5
A rows = []
B for n in [0, 1, 5, -2]:
C rows.append((n, f(n)))
D print(rows[0])
Line D — Only the first input-output pair is shown, so most of the evidence is thrown away. The whole table should be printed with print(rows).

Student with a class code? Join your class →