Validation, Verification and Testing: Computer Science 0478 (Cambridge O Level / IGCSE)
Syllabus 7.5, 7.6, 7.7, 7.8, 7.9 · Strand 7 Algorithm design and problem-solving
- Questions
- 10
- Total marks
- 49
- Tier mix
- 10 Core
0 of 10 questions completed
Syllabus coverage
- 7.5 6 questions completed
- 7.6 3 questions completed
- 7.7 2 questions completed
- 7.8 2 questions completed
- 7.9 2 questions completed
A program is only as reliable as the data it is fed, so this topic covers the checks that keep bad data out and the process that catches remaining mistakes. Validation (syllabus 7.5) is an automatic check performed on input before it is accepted, and the syllabus names six kinds: range, length, type, presence, format and check digit checks, each suited to a different kind of mistake. Verification, by contrast, checks that data has been copied or entered correctly rather than that it makes sense, using a visual check (comparing input against a source) or a double entry check (typing the same value twice and comparing).
Choosing good test data is a skill in its own right (7.6): normal data should be accepted without triggering an error, abnormal data should be rejected, and extreme and boundary data probe the very edges of what is acceptable, where boundary data pairs the largest or smallest accepted value with the nearest rejected one. A trace table (7.7) documents a dry run of an algorithm step by step, recording how variables, outputs and user prompts change, which is exactly the skill needed to identify where a given algorithm goes wrong and to correct or rewrite it (7.8, 7.9).
The exam-style questions below are original, written to match this syllabus objective, and each is followed by a full worked solution so you can check your method step by step.
Question 1
A membership renewal form for a chess club will not let a member submit the form until the MemberNumber field has been typed into. The form cannot be submitted while this field is left empty, no matter what else has been entered correctly.
Which type of validation check is being applied to the MemberNumber field here?
Question 2
GreenCommute is a cycle-hire app used at a university campus. Riders unlock a bike by entering a HireCode shown on a label on the bike's frame.
(a) The app refuses to let a rider continue until at least one character has been typed into the HireCode field. Identify the validation check being used here, and state what the app should do if the field is left empty. [2]
(b) Every valid HireCode is exactly 8 characters long. Identify the validation check that tests this rule, and explain what would happen if a rider typed the 3-character code "GC4". [2]
(c) New riders fill in a paper sign-up form. A staff member then types each rider's chosen HelmetSize ("S", "M" or "L") into the app while looking at the paper form. Identify a suitable verification check for this step, and describe how it works. [2]
Question 3
A lift (elevator) in a 25-storey office tower accepts a floor request typed on its control panel. The lift only serves whole-number floors from −2 (the lowest basement level) up to 25 (the top floor). Any request outside this range is rejected. Floors 26 to 29 are mechanical plant levels and can never be requested.
A range check is used to validate the floor request against −2 to 25 inclusive.
(a) Give an example of normal test data for the floor-request field, and explain why it is normal. [2]
(b) Give an example of abnormal test data for the floor-request field, and explain why it is abnormal. [2]
(c) Give a pair of boundary test data for the upper limit of the floor-request field. One value that must be accepted, and the very next whole number, which must be rejected, and explain what this pair is testing. [2]
Question 4
A café's loyalty till records how much each customer spends during a morning shift. The pseudocode below reads a sequence of Spend amounts, one at a time, and stops as soon as −1 is entered. It then works out and outputs the average spend per transaction.
01 DECLARE Spend : REAL
02 DECLARE Total : REAL
03 DECLARE Count : INTEGER
04 Total ← 0
05 Count ← 0
06 INPUT Spend
07 WHILE Spend <> -1
08 Total ← Total + Spend
09 Count ← Count + 1
10 INPUT Spend
11 ENDWHILE
12 Average ← Total / Count
13 OUTPUT Average
(a) The algorithm is run once, using this input data, entered in the order shown: 10.50, 9.00,
16.50, −1. Complete a trace table showing the values of Spend, Total and Count, and state
the value that is output. [4]
(b) State what happens when the algorithm is run with −1 as the very first value entered, and explain how the pseudocode could be changed to prevent this problem. [3]
(c) Explain why −1, rather than 0, is a sensible sentinel value to mark the end of the input data for this algorithm. [1]
Question 5
A school library assigns every book a 6-digit BookID, then adds a 7th check digit so that a librarian can spot a mistyped code if the barcode scanner fails and the code has to be entered by hand.
The check digit is calculated as follows:
- Starting from the rightmost of the 6 digits, multiply that digit by 3.
- Multiply the next digit to its left by 1.
- Continue alternating ×3, ×1, ×3, ×1, ×3, ×1 all the way to the leftmost (6th) digit.
- Add together all six results.
- The check digit is whatever must be added to this total to reach the next multiple of 10 (if the total already ends in 0, the check digit is 0).
(a) Calculate the check digit for the BookID 481526, showing your working. [3]
(b) Write the complete 7-digit code, including the check digit, that would be printed on the book's label. [1]
(c) Describe how this check digit is used to validate the BookID when it is next entered into the library system. [2]
Question 6
A garden centre's stock system has a Quantity field for each item ordered. The system will only accept an entry into this field if every character typed is a digit. It rejects the entry immediately if even one letter or symbol is typed, no matter how many digits are entered and no matter how large or small the resulting number is.
Which type of validation check is being applied to the Quantity field here?
Question 7
An online plant nursery's order form validates two fields before an order can be placed.
(a) OrderCode must consist of exactly 2 uppercase letters followed by exactly 4 digits (for example, "RS1024"). Identify the validation check used to test this rule, give an example of an OrderCode that this check would reject, and explain why it is rejected. [3]
(b) Quantity must be a whole number from 1 to 50 inclusive, customers cannot order zero or a negative number of plants, and the nursery's delivery van cannot carry more than 50 plants in a single order. Identify the validation check used to test this rule, give an example of a Quantity value that this check would reject, and explain why it is rejected. [3]
Question 8
A garden centre is registering a new till operator. To set up the operator's 6-digit StaffPIN, the till requires the same 6 digits to be typed into two separate boxes on the screen, one straight after the other. The till compares the two typed entries character by character, and only saves the StaffPIN if the two entries are identical.
Which type of check is being used here?
Question 9
A website's registration form validates the Password field using a length check: a password must contain from 8 to 16 characters inclusive to be accepted.
(a) Give an example of normal test data for the Password field, and explain why it is normal. [2]
(b) Give TWO examples of extreme test data for the Password field. One for each edge of the accepted length, and explain why each is extreme. [2]
(c) Give an example of abnormal test data for the Password field, and explain why it is abnormal. [2]
Question 10
A weather station stores five overnight temperature readings (in °C) in an array. The pseudocode below is meant to find and output the highest of the five readings.
01 DECLARE Temp : ARRAY[1:5] OF INTEGER
02 DECLARE Highest : INTEGER
03 DECLARE i : INTEGER
04 Temp[1] ← -6
05 Temp[2] ← -2
06 Temp[3] ← -9
07 Temp[4] ← -1
08 Temp[5] ← -4
09 Highest ← 0
10 FOR i ← 1 TO 5
11 IF Temp[i] > Highest
12 THEN
13 Highest ← Temp[i]
14 ENDIF
15 NEXT i
16 OUTPUT Highest
(a) Complete a trace table showing the values of i, Temp[i] and Highest as the algorithm
executes, and state the value output. [4]
(b) The value that should be output is −1, since −1 is the highest of the five readings. Explain why the algorithm instead produces the value found in part (a), identifying the line responsible. [2]
(c) Rewrite lines 09 and 10 of the pseudocode so that the algorithm correctly finds the highest reading, even when every reading is negative. [2]