Community resourceWorksheet
1CP2-CT-9.4 Test trace debug and search checkpoint
Part 4 of 4 · 1CP2-CT-9 · Testing, structures and integrated solutions
This checkpoint assesses CT-9 and retrieves the formal methods needed to use it. It introduces no new list, file, trace or error technique.
Students will:
- select tests with inputs, expected results and reasons
- trace list traversal and search state
- diagnose a defect from its observed behaviour
- amend and test a complete search without unsupported shortcuts
Inside: 4 explanation cells, 1 fill-in-the-blanks cell, 4 written answers, 1 trace table, 2 multiple-choice questions and 1 Python task. 19 marks, about 45 minutes.
Series: 1CP2-CT-9 · Testing, structures and integrated solutions, part 4 of 4.
Shared by Coding PathwayVerified teacher
- 13 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Test, trace, debug and search checkpoint
This checkpoint assesses CT-9 and retrieves the formal methods needed to use it. It introduces no new list, file, trace or error technique.
- 7
- boundary
- conversion
- 8
A password length must be 8–16 characters inclusive. Give four tests with expected accepted/rejected outcomes.
Cover both limits and both outside values.
Students type their answer here.
Complete the trace table.
Record position, item, found and comparisons each pass.
Use one row for each pass through the loop. Fill in a box only when that value changes on that row, and leave the rest blank.
values = [3, 8, 5, 8]target = 8found = Falsecomparisons = 0for position in range(len(values) - 1, -1, -1):comparisons = comparisons + 1if values[position] == target and found == False:found = Trueprint(found)print(comparisons)
| Row | values | target | found | comparisons | position | values[position] == target and found == False | Output |
|---|---|---|---|---|---|---|---|
| 1 | |||||||
| 2 | |||||||
| 3 | |||||||
| 4 | |||||||
| 5 | |||||||
| 6 | |||||||
| 7 | |||||||
| 8 |
Why is a one-dimensional list appropriate for daily temperatures?
- AIt stores an ordered sequence of similar values under one name
- BIt automatically creates a database
- CIt prevents all invalid input
- DIt sorts values without code
Diagnose the fragment
def latest_match(values, target):
found_position = -1
for position in range(len(values) - 1, -1, -1):
if values[position] == target:
found_position = position
return found_position
The code keeps searching after a match and overwrites the position, so it returns the earliest matching index rather than the latest one.
Explain why [4, 7, 4] with target 4 returns position 0 instead of the required latest position 2.
Follow both matching iterations.
Students type their answer here.
Amend without using break
Add a Boolean condition so the first reverse match is stored and later matches cannot overwrite it. Return -1 when there is no match.
def latest_match(values, target):
found_position = -1
found = False
for position in range(len(values) - 1, -1, -1):
if values[position] == target:
found_position = position
return found_position
answer = latest_match([4, 7, 4], 4)
print(answer)Give one absent-target regression test and its expected result.
State the list, target and exact return value.
Students type their answer here.
Explain why a search function should return a position instead of only printing it.
Use reuse or testing.
Students type their answer here.
When is reverse search most likely to reduce comparisons?
- ATargets are usually near the end and the search can stop after a match
- BEvery target is absent
- CThe list is randomly rearranged after every comparison
- DThe code must visit every item regardless
Route forward
You have completed CT-9. CT-10 will extend these test, trace and repair methods to records and two-dimensional structures.