iGCSE Computer Science - Distance Learning

Tutor Marked Assignment 6
Tutor Marked Assignment 8 (Programming)

Validation & Verification

When devloping your programs, it is important that you consider whether any inputs from the user will break your program. Making a program that considers plans for this in advance is known as defensive design and will make your program robust.

Using techniques like validation and verification help to make your program more robust as they prevent incorrect data from entering the system.

The phrase commonly used with this is “Garbage in, Garbage out”.

In the video below, Holly introduces different methods of defensive design in algorithms – specifically validation and verification.

Verification

Verification is useful for user input when you want to check that what your user is inputting is what they wanted to input. For example, when entering a new password a website will often ask the user to input it twice to ensure that they didn’t make a spelling error.

password1 = INPUT
password2 = INPUT

WHILE password1 <> password2 DO
OUTPUT "passwords do not match "
password1 = INPUT
password2 = INPUT
END WHILE

Validation

Validation is applying certain rules to the data that your user inputs into the system. By adding validation to your code, it prevents the program from crashing when incorrect data is entered.

There are a number of different types of validation that can be used within your programs – these also appear in your exam in paper 2 under program design. You may be asked to describe the terms, or use them as part of your pseudocode programs.

  • Type Checks
  • Length Checks
  • Presence Checks
  • Format Checks
  • Range Checks

Each of these types of checks can be combined together to make sure that your user is entering correct data into the system.

When a user enters data incorrectly, it is usual for a program to prevent them from moving forward until the data is correct. Knowing that we want our user to keep entering data until they get it right indicates that we want to use a type of loop that will keep repeating until the condition is met. In this case, either a WHILE or REPEAT UNTIL loop is best.

age = INPUT

WHILE age.Type <> Integer DO

    OUTPUT "Age nust be a whole number "

    age = INPUT
END WHILE

Task 1 – Practical Task

Complete the python program below to create a validation routine:

Task 2 – Exam Style Questions

Download the exam style questions below to test your understanding of robust programming methods. The questions that you may be asked are wide ranging and may be anything from matching definitions to writing pseudocode.