← ACARA Digital Technologies Years 9–10

Storing test cases as a list of tuples

A list of (input, expected) tuples. Each tuple is one test case, so a loop can run many tests stored in one variable. Add a new tuple to add a new test.

Understanding Storing test cases as a list of tuples in ACARA Digital Technologies Years 9–10

What it does: The tuple (4, 16) means input 4 should give expected output 16. One tuple is one test case. append() takes one item. The double brackets mean the tuple (10, 100) is that one item. Without them, Python raises a TypeError. Keeping all the tests in one list means a for loop can go through them one at a time. tests is a list, not a function, so it has no brackets after it. Each tuple unpacks into two names. Tuples in a list must be separated by a comma. Leaving it out is a SyntaxError.

Common mistakes: The tuples in the list are not separated by a comma, so Python raises a SyntaxError. It should be tests = [(5, 25), (0, 0)]. The list is missing its closing square bracket, so Python raises a SyntaxError. It should end with )] like tests = [(5, 25), (0, 0)].

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 591–622) 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
Which line stores two test cases for a square function, each as (input, expected)?
tests = [(5, 25), (0, 0)]tests = (5, 25, 0, 0)
Matches
tests = [(5, 25), (0, 0]
↓
The second tuple is closed with a square bracket ] instead of a round bracket ), so the code has a syntax error.
Applying
Meanings
Term
tests = [(5, 25), (0, 0)]
Meaning
A list of (input, expected) tuples. Each tuple is one test case, so a loop can run many tests stored in one variable. Add a new tuple to add a new test.
Practice
tests = [(5, 25), (0, 0)]
Testing
Gaps
= [(5, 25), (0, 0)]
Check Answer
Spots
1tests = [(5, 25) (0, 0)]
2for n, want in tests:

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

The 'Abyssal Dragon' badge — Deep Sea Legend, 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 line stores two test cases for a square function, each as (input, expected)?
A. tests = (5, 25, 0, 0)
B. tests = [(5, 25), (0, 0)] ✓
A list of tuples keeps each input paired with its expected output. One flat tuple loses the pairs.
2. In tests = [(5, 25), (0, 0)], what does the tuple (5, 25) represent?
A. One test case: input 5, expected output 25 ✓
B. Two separate inputs, 5 and 25
Each tuple is (input, expected). So 5 is the input and 25 is the answer we expect.
3. How many test cases are in tests = [(2, 4), (3, 9), (4, 16)]?
A. 3 ✓
B. 6
Each tuple is one test case, so three tuples means three test cases, even though there are six numbers.
4. Which is the correct way to add a new test case with input 10 and expected 100?
A. tests.append((10, 100)) ✓
B. tests.append(10, 100)
append() takes one item. The double brackets mean the tuple (10, 100) is that one item. Without them, Python raises a TypeError.
5. Why store test cases in a list of tuples instead of writing a separate variable for each one?
A. Python only lets you test code that uses a list
B. A loop can run every test case stored in one variable ✓
Keeping all the tests in one list means a for loop can go through them one at a time.

Match the Pairs

tests = [(5, 25), (0, 0)] → Creates a list holding two test cases, each stored as an (input, expected) tuple
tests.append((3, 9)) → Adds a new test case with input 3 and expected output 9 to the end of the list
Each test case is one tuple that pairs an input with its expected output → (4, 16)
A loop can unpack each tuple in the list so every test case is run in turn → for x, expected in tests:
tests = [(5, 25), (0, 0] → The second tuple is closed with a square bracket ] instead of a round bracket ), so the code has a syntax error.
tests = [(5, 25), (0)] → (0) is not a tuple and only holds the input, so the expected output is missing and this test case is incomplete.

Key Term

tests = [(5, 25), (0, 0)]
A list of (input, expected) tuples. Each tuple is one test case, so a loop can run many tests stored in one variable. Add a new tuple to add a new test.

Fill in the Blanks

1. tests = [(5, 25), (0, 0)]
Hint: Type the variable name that holds the whole list of test cases.
2. # expected is the square of the input tests = [(3, 9), (0, 0)]
Hint: Type the expected output for the input 3 (the comment tells you the rule).
3. tests = [(5, 25), (0, 0)] tests.append((4, 16))
Hint: Type the list method that adds a new test case tuple to the end of the list.
4. tests = [(2, 4), (3, 9)] for inp, expected in tests: print(inp, expected)
Hint: Type the name of the list that the loop should run through, one test case at a time.
5. tests = [(5, 25), (0, 0)] # expected output of the first test case print(tests[0][1])
Hint: Type the index that selects the first tuple in the list.

Spot the Error

Question 1
A tests = [(5, 25) (0, 0)]
B for n, want in tests:
C print(n, want)
Line A — The tuples in the list are not separated by a comma, so Python raises a SyntaxError. It should be tests = [(5, 25), (0, 0)].
Question 2
A passed = 0
B tests = [(5, 25), (0, 0)
C for n, want in tests:
D if n * n == want:
E passed += 1
Line B — The list is missing its closing square bracket, so Python raises a SyntaxError. It should end with )] like tests = [(5, 25), (0, 0)].
Question 3
A tests = [(2, 4), (3, 9)]
B tests.add((4, 16))
C for n, want in tests:
D print(n, want)
Line B — Lists have no add() method, so this raises an AttributeError. To add a new test case tuple to a list, use tests.append((4, 16)).
Question 4
A tests = [(2, 4), (3, 9)]
B for n, want in tests:
C got = n * n
D print(got = want)
Line D — A single = is not a comparison, so print(got = want) is an error. To check whether the actual result matches the expected result, use ==, as in print(got == want).
Question 5
A tests = [(2, 4), (3, 9)]
B for test in tests:
C n = test[2]
D want = test[1]
E print(n, want)
Line C — Each test tuple has only two items, at index 0 and 1, so test[2] causes an IndexError. The input is the first item, so it should be n = test[0].

Student with a class code? Join your class →