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.

Fill in the blanks3 marks
For length 8, the last index is gap 1. A test at an inclusive limit is gap 2 data. CSV numeric text needs gap 3 before arithmetic.
  • 7
  • boundary
  • conversion
  • 8
Written answer4 marks

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.

Trace table6 marks

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.

ProgramPython
  1. values = [3, 8, 5, 8]
  2. target = 8
  3. found = False
  4. comparisons = 0
  5. for position in range(len(values) - 1, -1, -1):
  6. comparisons = comparisons + 1
  7. if values[position] == target and found == False:
  8. found = True
  9. print(found)
  10. print(comparisons)
Trace table with 7 columns
Rowvaluestargetfoundcomparisonspositionvalues[position] == target and found == FalseOutput
1
2
3
4
5
6
7
8
Multiple choice1 mark

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.

Written answer2 marks

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.

Coding task5 marks
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)
Written answer1 mark

Give one absent-target regression test and its expected result.

State the list, target and exact return value.

Students type their answer here.

Written answer2 marks

Explain why a search function should return a position instead of only printing it.

Use reuse or testing.

Students type their answer here.

Multiple choice1 mark

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.