GCE O-Level · Computing (7155)

Testing and Debugging: Practice Questions

5 multiple-choice questions marked as you go, and 5 written questions with worked solutions. All on Testing and Debugging.

10 questions28 marksFree, no account
Question 1
1 mark

A programmer is checking if an input string code has a length of exactly 5 characters and contains only digits. Which validation technique is primarily being used for the length check?

Question 2
1 mark

A data validation routine checks if a value \(Y\) (Year of Birth) is within the valid range \(1900 \le Y \le 2024\). To perform boundary value analysis, which of the following sets of test data should be used to test the limits of this range check?

Question 3
1 mark

A programmer writes a script to calculate the square root of a user-provided number using math.sqrt(). If the user enters a negative number, the program immediately stops and displays a "ValueError". Which type of error does this represent?

Question 4
1 mark

Study the following Python code segment:

total = 0
for i in range(5):
  if i % 2 == 0:
    total = total + i

What is the final value of total after the loop finishes?

Question 5
1 mark

Consider the following Python code intended to sum all odd integers in the list vals = [1, 2, 3, 4, 5]:

total = 0
i = 0
while i <= len(vals):
  if vals[i] % 2 != 0:
    total += vals[i]
  i += 1

What will happen when this code is executed?

Question 6
4 marks

A programmer performs a manual dry run of the following algorithm using a trace table:
1. Set \(x = 10\)
2. For each \(i\) in the range from \(1\) to \(3\) (inclusive):
   a. \(x = x + i\)
What is the final value of \(x\) recorded in the trace table after the loop finishes?

Write your answer out first, then check it against the worked solution.

Question 7
5 marks

A program is designed to validate a date string in the format "DD-MM". Describe how the program should sequentially use a length check, a format check, and range checks to ensure that a user input like "32-01" is rejected. Specify what each check would look for in this specific input.

Write your answer out first, then check it against the worked solution.

Question 8
4 marks

A system requires a product code to follow the format of exactly three uppercase letters followed by exactly three digits (e.g., \(ABC123\)). A user enters \(AB1234\). Name two specific types of data validation checks that would detect this error and explain how each check would identify the mismatch.

Write your answer out first, then check it against the worked solution.

Question 9
4 marks

A software developer is designing a validation routine for a new user account. The username must satisfy the following conditions: it must not be left blank, it must be between \(5\) and \(12\) characters long, and it must contain only alphanumeric characters.

(a) Identify the three specific types of data validation checks being used to enforce these conditions.
(b) For the length requirement (between \(5\) and \(12\) characters), provide one example of boundary test data and one example of invalid (error) test data.

Write your answer out first, then check it against the worked solution.

Question 10
6 marks

Perform a manual dry run of the following algorithm using a trace table to identify duplicate adjacent numbers in a list.

Algorithm:
1. Set \(L = [5, 2, 8, 8, 3]\)
2. Set \(found = False\)
3. Set \(i = 0\)
4. While \(i < 4\) and \(found\) is \(False\):
    a. If \(L[i] == L[i+1]\):
        i. \(found = True\)
        ii. \(duplicate = L[i]\)
    b. \(i = i + 1\)

Provide a trace table showing the values of \(i\), \(L[i]\), \(L[i+1]\), and \(found\) at the start of each loop iteration until the algorithm terminates.

Write your answer out first, then check it against the worked solution.

* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.

You've seen the model answer. Now get yours marked.

This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.

Want more questions like these? Get a fresh set on this topic, graded as you go.

Practice More