Validation & Testing

Validation & Verification

Validation checks that data entered is REASONABLE and meets criteria before processing (range, length, type, presence, format). Verification checks that data has been ACCURATELY copied or entered (double entry, visual check). Both are needed for data integrity.

17.1 What is Validation?

Validation is the process of checking that data entered is REASONABLE and MEETS CRITERIA before it is stored or processed. It is performed at INPUT time — the program checks the value immediately and either accepts or rejects it.

  • Performed at input time — the check runs as the data is entered.
  • Checks reasonableness — does the data meet the defined rules?
  • Does NOT check correctness — a valid age (e.g. 25) may still be the wrong age for the person.
  • Five common types — Range, Length, Type, Presence, Format.

Key idea: validation asks "Is the data reasonable?" — it does NOT ask "Is the data true?". A range check on Age 0–120 accepts 25, even if the user is actually 47. Correctness is the job of verification.

Common mistake: thinking validation guarantees correctness. It only guarantees reasonableness. To check correctness, you need verification (e.g. double entry or visual check).

17.2 Range Check

A range check verifies that an input value falls within a specified lower and upper bound. It is typically used for numeric data such as age, exam score, temperature, or quantity.

DECLARE Age : INTEGER
OUTPUT "Enter age: "
INPUT Age
IF Age >= 0 AND Age <= 120 THEN
  OUTPUT "Valid age"
ELSE
  OUTPUT "Invalid age"
ENDIF
  • Inclusive bounds>= and <= accept values AT the boundary.
  • Two conditions joined with AND — both must be true for the value to pass.
  • Typical uses — age 0–120, exam score 0–100, month 1–12, day 1–31.
  • Rejects — out-of-range values such as Age = 150 or Score = -5.

Exam tip: if a question says "value must be between X and Y", that is a range check. Use IF Value >= X AND Value <= Y THEN ... ELSE ... ENDIF. Do not forget to handle the boundary values correctly.

17.3 Length Check

A length check verifies that a string input has the correct number of characters. The rule can be a minimum length, a maximum length, or an exact length. It uses the built-in LENGTH() function.

DECLARE Password : STRING
OUTPUT "Enter password: "
INPUT Password
IF LENGTH(Password) >= 8 THEN
  OUTPUT "Valid password"
ELSE
  OUTPUT "Password too short"
ENDIF
  • Minimum lengthLENGTH(Pwd) >= 8.
  • Maximum lengthLENGTH(Tweet) <= 280.
  • Exact lengthLENGTH(Phone) = 11.
  • Uses LENGTH() built-in — returns the character count as an INTEGER.

Watch out: a length check does NOT guarantee strength or quality. A password of "aaaaaaaa" passes LENGTH >= 8 but is very weak. Strength also depends on character variety — uppercase, digits, symbols.

Exam tip: the LENGTH() function returns an INTEGER, so you can compare it directly with >=, <=, =, <>. Always use LENGTH() — never count characters manually.

17.4 Type Check and Presence Check

A type check verifies that the input is of the correct data type (e.g. INTEGER, REAL, STRING, BOOLEAN). A presence check verifies that a field is not empty — i.e. the user has supplied a value.

  • Type check — input must match the declared data type. Declaring Age : INTEGER and using INPUT Age rejects non-numeric input.
  • Presence check — input must not be empty. Test with IF Name = "" THEN.
  • Used together — a name field needs both a presence check (not empty) AND a type check (must be STRING).
DECLARE Name : STRING
OUTPUT "Enter name: "
INPUT Name
IF Name = "" THEN
  OUTPUT "Name is required"
ELSE
  OUTPUT "Valid name"
ENDIF

The above example performs a presence check on the Name field. If the user presses Enter without typing anything, Name becomes the empty string "" and the check fails with "Name is required".

How type checks work in CIE pseudocode: when a variable is declared as INTEGER and the user enters text like "twenty", the INPUT statement fails because text cannot be stored as an integer. The declared type acts as an implicit type check.

17.5 What is Verification?

Verification is the process of checking that data has been ACCURATELY COPIED or ENTERED. It is performed AFTER data entry — not at input time. The two main methods are double entry and visual check (proofreading).

  • Double entry — user enters the same data twice; system compares the two entries.
  • Visual check — user proofreads the entered data against the source.
  • Performed AFTER input — not at the moment of entry.
  • Catches transcription errors — e.g. typing 25 instead of 52.
DECLARE Email1, Email2 : STRING
OUTPUT "Enter email: "
INPUT Email1
OUTPUT "Confirm email: "
INPUT Email2
IF Email1 = Email2 THEN
  OUTPUT "Email verified"
ELSE
  OUTPUT "Emails do not match - re-enter"
ENDIF

This is double-entry verification. The user enters the email address twice. If the two entries match, the data is verified. If they differ, the user must re-enter — the mismatch suggests a typing error.

AspectValidationVerification
QuestionIs the data reasonable?Was the data entered correctly?
WhenAt INPUT timeAFTER input
MethodsRange, Length, Type, Presence, FormatDouble entry, Visual check
CatchesUnreasonable values (age 999)Transcription errors (52 vs 25)

Key idea: validation and verification are COMPLEMENTARY. Validation rejects obviously bad input (age 999). Verification catches typing slips (entering 25 instead of 52 for an account number). You need both for clean data.

17.6 Key Points Summary

A quick recap of everything covered on validation and verification:

  • Validation = reasonableChecks data entered is reasonable and meets criteria.
  • Verification = accurately enteredChecks data has been accurately copied or entered.
  • Validation at INPUT timePerformed as data is entered — immediate accept/reject.
  • Verification AFTER inputPerformed after entry — comparison or proofread.
  • Five validation typesRange, Length, Type, Presence, Format.
  • Two verification methodsDouble entry (enter twice, compare), Visual check (proofread).
  • Range checkIF Value >= Min AND Value <= Max THEN ... — inclusive bounds.
  • Length checkIF LENGTH(Str) >= N THEN ... — uses the LENGTH() built-in.
  • Type checkDeclared data type acts as implicit type check during INPUT.
  • Presence checkIF Field = "" THEN reject — field must not be empty.
  • Validation ≠ correctnessA valid value (age 25) may still be wrong for the person.
  • Both neededValidation + verification together give the best data integrity.

Exam tip: in an exam, always state WHICH type of validation is being used (range, length, type, presence, or format) and explain WHY. For verification questions, name the method (double entry OR visual check) and describe how it works.

Question Bank

Answer all questions, then press Submit Quiz to see your score.

0/12 answered

Question 1Multiple Choice

What is validation?

Question 2True / False

Validation is performed at INPUT time, before data is stored or processed.

Question 3Multiple Choice

What is the output of this code?

DECLARE Age : INTEGER
OUTPUT "Enter age: "
INPUT Age
IF Age >= 0 AND Age <= 120 THEN
  OUTPUT "Valid age"
ELSE
  OUTPUT "Invalid age"
ENDIF
// User enters: 25

Question 4Multiple Choice

What is the output of this code?

DECLARE Password : STRING
OUTPUT "Enter password: "
INPUT Password
IF LENGTH(Password) >= 8 THEN
  OUTPUT "Valid password"
ELSE
  OUTPUT "Password too short"
ENDIF
// User enters: "abcdefg"

Question 5Multiple Choice

Which validation type ensures that a field has not been left empty?

Question 6True / False

Verification checks that data has been accurately copied or entered.

Question 7Multiple Choice

Which is a method of verification?

Question 8True / False

Validation can guarantee that data is factually correct.

Question 9Multiple Choice

What is the output of this code?

DECLARE Name : STRING
OUTPUT "Enter name: "
INPUT Name
IF Name = "" THEN
  OUTPUT "Name is required"
ELSE
  OUTPUT "Valid name"
ENDIF
// User presses Enter without typing anything

Question 10Multiple Choice

Which BEST describes the difference between validation and verification?

Question 11Multiple Choice

Which list contains ONLY validation types?

Question 12True / False

Both validation and verification are needed for full data integrity.

Answer all 12 questions to enable submission.