Ch 3 · 7 Algorithm Design: Validation, Verification and Test Data · O Level Computer Science 2210

Topic 3 of 4 in Algorithm Design and Problem-Solving — O Level Computer Science 2210 — 39 lessons.

Introduction

"Rubbish in, rubbish out." A program is only as good as the data it is given. Validation and verification stop bad data getting in, and test data checks that the program copes with every kind of input. (Syllabus topic 7, outcomes 5–6.)

Key ideas — Validation

Validation is an automatic check by the program that input data is reasonable and sensible (it obeys set rules) before it is accepted. It does not check that the data is correct: an age of 15 might be valid but still wrong.

🧑‍🏫 Teacher's explanation

Imagine you are a security guard at a concert. You check if people have a ticket (Presence Check) and if they are wearing the right clothes (Format Check). You also check if they are the right age (Range Check). However, even if they have a ticket and are the right age, they might still be the wrong person! This is the core difference between validation and verification.

📖 Definitions

🔍 Worked example — Easy

A program requires a user to enter a score between 0 and 40 inclusive. Identify if the following inputs are 'Valid' or 'Invalid' based on a range check: 0, 25, 40, 41, -1.

🔍 Worked example — Standard

A password must be between 8 and 12 characters long. Determine the type of test data for the following inputs: (a) 'password123', (b) 'abc', (c) '12345678', (d) '123456789012345'.

🔍 Worked example — Exam-style

Write a pseudocode algorithm that uses a REPEAT...UNTIL loop to ensure a user enters a 5-digit integer for a PIN. The program should only accept the input if it is exactly 5 digits long and contains only numbers.

⚠️ Common errors

🧠 Quick check 1

🧠 Quick check 2

🎯 Exam question

Key ideas — Verification

Verification checks that data has been entered or copied accurately, that it matches the original.

🧑‍🏫 Teacher's explanation

Imagine you are writing a long address on an envelope. Validation is like a spell-checker that tells you if you've typed a word that doesn't exist (e.g., 'Streeet'). Verification is different: it's like looking at your handwritten note and the envelope to make sure you didn't accidentally write '123 Main St' when the note actually said '123 Mane St'. Even if 'Mane St' is a perfectly valid street name, it's not the one you intended.

📖 Definitions

🔍 Worked example — Easy

A user is setting a new PIN. Using the provided pseudocode logic, trace the execution if the user inputs '1234', then '1234', then '5678', then '5678'.

🔍 Worked example — Standard

A system requires a double entry check for a username. The user enters 'Admin' then 'Admin'. Then the user enters 'User1' then 'User2'. How many times must the user be prompted to enter the data?

🔍 Worked example — Exam-style

A programmer uses a visual check for a student's ID number. The original ID is A1234B. The user types A1234B into the system. The programmer also uses a double entry check. If the user types A1234B then A1234C, what is the result?

⚠️ Common errors

🧠 Quick check 1

🧠 Quick check 2

🎯 Exam question

a) State one advantage and one disadvantage of using a visual check. [2]

Key ideas — Test data

When asked for test data, give the value, its type, and the expected result (accepted or rejected), for example: "101, boundary, rejected".

🧑‍🏫 Teacher's explanation

Imagine you are designing an automated vending machine that only accepts coins between 10c and 20c. If someone puts in a 5c coin, the machine must reject it. If they put in a 15c coin, it should work perfectly. If they try to jam a 50c coin in, the machine must detect it is out of range. Testing is the process of intentionally trying to 'break' the machine using different types of inputs to ensure it behaves exactly as intended.

📖 Definitions

🔍 Worked example — Easy

A system requires a user to enter an age between 0 and 120 inclusive. Identify the test data types for the following values: 25, -5, 120, 121.

🔍 Worked example — Standard

A password must be between 8 and 16 characters long. Provide one 'boundary' test case that should be accepted and one 'boundary' test case that should be rejected.

🔍 Worked example — Exam-style

A variable X is defined as an integer where 10 ≤ X ≤ 50. Complete the table for test data: (a) A value that is normal, (b) A value that is extreme, (c) A value that is abnormal.

⚠️ Common errors

🧠 Quick check 1

🧠 Quick check 2

🎯 Exam question

State one piece of normal test data, one piece of abnormal test data, and one piece of boundary test data. For each, state whether it should be accepted or rejected. [4 marks]

Worked example

A program accepts a number of tickets from 1 to 6. Suggest test data of each type, with the expected outcome.

🔍 Worked example — Easy

A system requires a password of exactly 8 characters. Suggest one piece of 'normal' test data and one piece of 'abnormal' test data.

🔍 Worked example — Standard

A temperature sensor accepts values in the range -50 to 100 degrees Celsius. Complete the table for test data types.

🔍 Worked example — Exam-style

A program accepts a number of tickets from 1 to 6. Identify the outcome for the following test data: 3, 10, 1, 6, 0, 7.

⚠️ Common errors

Common mistakes

Practice

Answers: (1) Validation automatically checks that data is reasonable/sensible; verification checks that data has been entered accurately (matches the original). (2) (a) presence check; (b) range check; (c) length check. (3) The data is entered twice and the computer compares the two entries; if they do not match, it must be re-entered. (4) Normal: 165; abnormal: 300 or "tall"; extreme: 100 and 220; boundary: 99 (rejected) and 100 (accepted), or 220 (accepted) and 221 (rejected). (5) REPEAT INPUT Age UNTIL Age >= 11 AND Age <= 18 (with an error message inside the loop if the age is out of range).

Summary

All chapters in Algorithm Design and Problem-Solving

  1. 7 Algorithm Design: Development Life Cycle and Design Methods
  2. 7 Algorithm Design: Standard Methods of Solution
  3. 7 Algorithm Design: Validation, Verification and Test Data
  4. 7 Algorithm Design: Trace Tables, Errors and Writing Algorithms