StudyVault
Home Unit Overview Exam Technique Revision Techniques ← Previous Lesson Next Lesson →

← Back to Dashboard

Overlay:
0:00 / 0:00 Narration generated using AI text-to-speech.

Robust Programming: Validation, Authentication and Testing

What Is Robust Programming?

A robust program does not crash when something goes wrong. Users make mistakes — they enter text where a number is expected, leave fields blank, or type a value that is out of range. A robust program anticipates these problems and deals with them gracefully. Writing robust code means building in three things: data validation, authentication, and testing.

Data Validation

Data validation checks that input data is sensible and within the expected rules before the program uses it. Validation does not guarantee the data is accurate or true — it only confirms it meets the required format or range. For example, a date of birth field can be validated to ensure the year is between 1900 and 2025, but validation cannot check whether that is your real date of birth.

The specification identifies three specific validation checks you need to be able to write:

  • Minimum length check — confirms the entered string has at least a required number of characters. For example, a username might need at least three characters.
  • Empty string check (presence check) — confirms the user has entered something at all rather than leaving the field blank.
  • Range check — confirms that a number falls within an acceptable range, for example between 1 and 10.

Below is a routine that repeatedly asks for a score between 1 and 10. It uses a range check. The REPEAT–UNTIL loop keeps asking until valid input is received.

SUBROUTINE getValidScore()
   REPEAT
      OUTPUT "Enter a score (1–10): "
      score ← STRING_TO_INT(USERINPUT)
   UNTIL score >= 1 AND score <= 10
   RETURN score
ENDSUBROUTINE

A minimum length check for a username would look like this:

SUBROUTINE getUsername()
   REPEAT
      OUTPUT "Enter username (min 3 chars): "
      username ← USERINPUT
   UNTIL LEN(username) >= 3
   RETURN username
ENDSUBROUTINE
Key Fact

The three validation checks required by the specification are: minimum length (LEN check), empty string (presence check), and range check (value between two bounds). Validation ensures data is reasonable — not necessarily correct.

Authentication Routines

Authentication is the process of confirming that a user is who they claim to be. You need to be able to write a simple authentication routine that checks a username and password. In exam questions, passwords are stored as plain text — you are not expected to encrypt them.

A simple authentication routine compares the username and password entered by the user with stored values. If both match, access is granted. Most real systems also limit the number of attempts to prevent someone trying thousands of combinations, but even a simple three-attempt limit is good practice and may appear in exam questions.

This routine allows three attempts before locking out the user:

storedUser ← "admin"
storedPass ← "pass123"
attempts ← 0
access ← FALSE

REPEAT
   OUTPUT "Username: "
   user ← USERINPUT
   OUTPUT "Password: "
   pass ← USERINPUT
   attempts ← attempts + 1
   IF user = storedUser AND pass = storedPass THEN
      access ← TRUE
   ENDIF
UNTIL access = TRUE OR attempts = 3

IF access THEN
   OUTPUT "Access granted"
ELSE
   OUTPUT "Account locked"
ENDIF

Testing: Types of Test Data

Testing checks that a program behaves correctly for all possible inputs, not just the obvious cases. You must be able to describe and select three types of test data:

  • Normal (typical) data — values that are well within the valid range. They should be accepted and processed correctly. For a range of 1–10, normal data might be 5 or 7.
  • Boundary (extreme) data — values at the very edge of the valid range, and just outside it. For a range of 1–10, boundary data is 0, 1, 10 and 11 — both sides of each boundary. Boundary data catches off-by-one errors that are easy to introduce when writing conditions.
  • Erroneous data — values that are completely outside the expected range or of the wrong type altogether. For a number field, entering the word “banana” or a negative number like −5 is erroneous data. The program should reject this without crashing.
Key Fact

Boundary data is both sides of each limit. For the range 1–10, the boundary values are 0, 1, 10 and 11. A common mistake is to give only one boundary value — you need all four to test both bounds fully.

Types of Error

When a program does not work as expected, the fault is usually one of two types. A syntax error breaks the rules of the programming language — a missing bracket, a misspelled keyword, or incorrect indentation. The program will not run at all until syntax errors are fixed. A logic error allows the program to run but produces wrong results. For example, using “>” instead of “>=” in a boundary check, or calculating the average by dividing by the wrong value.

Logic errors are harder to find than syntax errors because the program does not tell you something is wrong — it just silently gives the wrong answer. Careful testing with all three types of test data is the best way to expose logic errors before a program is released.

Practice Questions

Test yourself on this lesson. Pick a question, write your answer, then get it marked.

AI feedback
AI feedback is guidance, not a final exam mark. If you disagree, your teacher's view is always the tie-breaker.
← Back to unit
Video

© 2026 StudyVault · About · FAQ · Copyright & IP · Privacy · Disclaimers

StudyVault Education Ltd · registered in England and Wales, company no. 17490559 · 71–75 Shelton Street, London WC2H 9JQ