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

Test, trace, debug and refine cyclerequirementsexpectedbehaviourteststrace /evidencecorrectregression tests +fitness judgementCorrect output, readability and efficiency are related but distinct judgements.

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.

Fill in the blanks3 marks
A test kept to protect behaviour after a change is a gap 1 test. Evidence of state changes comes from a gap 2. A correction must be checked against the original gap 3.
  • regression
  • requirement
  • trace
Written answer2 marks

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.

Multiple choice1 mark

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]
Written answer3 marks

Explain both required corrections.

Address the boundary and first-match requirement separately.

Students type their answer here.

Trace table5 marks

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.

ProgramPython
  1. records = [["A", 50], ["B", 70], ["C", 80]]
  2. answer = []
  3. for row in records:
  4. if row[1] > 50:
  5. answer = row
  6. print(answer)
Trace table with 5 columns
Rowrecordsanswerrowrow[1] > 50Output
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.

Coding task6 marks
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)
Written answer2 marks

State two regression tests to rerun after the amendment and explain what each protects.

Use different required behaviours.

Students type their answer here.

Written answer2 marks

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.

Multiple choice1 mark

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.