Topic 7 · Algorithm design and problem-solving

Validation and verification

Video lesson: Validation and verification▶ Watch the video lessonShort, exam-focused explanation of this topic on the CS with Aamir YouTube channel.

When data is entered into a computer system, two kinds of checks help keep it accurate. Validation checks that the data is reasonable and sensible. Verification checks that the data has been entered or copied exactly as it was in the original.

Validation checks

Validation is an automatic check carried out by the program. It can reject impossible data, but it cannot tell whether data is actually correct – a sensible but wrong date of birth will still pass.

CheckWhat it doesExample
Range checkChecks the value is between a lower and an upper limitA mark must be from 0 to 100
Length checkChecks the number of characters is exact or within limitsA password must have at least 8 characters
Type checkChecks the data is the correct data typeAge must be a whole number
Presence checkChecks that the field has not been left emptyAn email address must be entered
Format checkChecks the data follows a set patternA student ID must be two letters followed by four digits
Check digitA final digit calculated from the other digits, used to find errors in numbersThe last digit of an ISBN or a barcode

Pseudocode example: a range check

REPEAT
   OUTPUT "Enter a mark from 0 to 100"
   INPUT Mark
   IF Mark < 0 OR Mark > 100
      THEN
         OUTPUT "Invalid mark, please try again"
   ENDIF
UNTIL Mark >= 0 AND Mark <= 100

The loop keeps asking until the mark is within the range, so invalid data can never be stored.

Verification methods

Test data

To test that a validation routine works, use four types of test data. For a mark that must be from 0 to 100:

TypeMeaningExample
NormalData that should be accepted45
Abnormal (erroneous)Data that should be rejected-12, 150, "ten"
ExtremeThe largest and smallest values that should be accepted0 and 100
BoundaryA value at the limit that is accepted, and the value just outside it that is rejected0 and 100 (accepted); -1 and 101 (rejected)

Exam tips

Want the full topic notes, slides and worksheets? See Notes & Slides, practise with the free CS with Aamir Quiz App, or order the O Level Computer Science Study Guide.