Community resourceWorksheet
1CP2-CT-10.4 Test trace debug and refine an integrated program
Part 4 of 5 · 1CP2-CT-10 · Integrated programming and data structures
Refinement is evidence-led. Translate requirements into expected behaviour and design tests. Trace a failure, locate its cause and amend the code. Then rerun both the failing test and earlier regression tests. Correctness, readability and efficiency are separate qualities.
Students will:
- turn requirements into expected test behaviour
- trace an integrated program to locate a defect
- amend code while preserving correct behaviour
- rerun failing and regression tests after refinement
Inside: 5 explanation cells, 1 fill-in-the-blanks cell, 4 written answers, 2 multiple-choice questions, 1 trace table and 1 Python task. 20 marks, about 45 minutes.
Series: 1CP2-CT-10 · Integrated programming and data structures, part 4 of 5.
Shared by Coding PathwayVerified teacher
- 14 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 refine an integrated program
Refinement is evidence-led. Translate requirements into expected behaviour and design tests. Trace a failure, locate its cause and amend the code. Then rerun both the failing test and earlier regression tests. Correctness, readability and efficiency are separate qualities.
1. Use a complete development cycle
A correct output for one input does not prove all paths. A readable identifier does not guarantee correct logic. Fewer comparisons may improve efficiency, but only if the program still meets every requirement.
- regression
- requirement
- trace
A search should return the first row with score at least 50 or [] if none. Give an equality test and a multiple-match test, with expected results.
Check the boundary and first-match rule.
Students type their answer here.
2. Locate the defect
def first_pass(records):
answer = []
for row in records:
if row[1] > 50:
answer = row
return answer
There are two logic errors: equality at 50 is excluded, and later matches overwrite earlier ones.
For [["A", 50], ["B", 70], ["C", 80]], which row is returned by the faulty code?
- A[]
- B[A, 50]
- C[B, 70]
- D[C, 80]
Explain both required corrections.
Address the boundary and first-match requirement separately.
Students type their answer here.
Complete the trace of the faulty function body.
Record row, condition and answer after each iteration.
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.
records = [["A", 50], ["B", 70], ["C", 80]]answer = []for row in records:if row[1] > 50:answer = rowprint(answer)
| Row | records | answer | row | row[1] > 50 | Output |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 | |||||
| 7 |
3. Amend and protect behaviour
Repair the function without break. Preserve [] when absent and the complete first matching row when present.
def first_pass(records):
answer = []
for row in records:
if row[1] > 50:
answer = row
return answer
result = first_pass([["A", 50], ["B", 70], ["C", 80]])
print(result)State two regression tests to rerun after the amendment and explain what each protects.
Use different required behaviours.
Students type their answer here.
Explain one readability refinement and one efficiency refinement that would not change required output.
Use identifiers/layout and comparisons/work performed.
Students type their answer here.
What makes a refinement defensible?
- AIt makes the code shorter at any cost
- BTests show requirements remain satisfied and evidence supports the claimed improvement
- CIt removes comments
- DIt changes expected results
Route forward
The final CT checkpoint now asks you to interpret, trace, test, amend and construct with reduced scaffolding before full IDE and examination-paper practice.