Welcome to Validation, Verification, and Test Data
Have you ever tried to sign up for a website and it wouldn't let you click "Submit" because your password was too short or you forgot to enter your email? That isn't the computer being annoying—it’s the computer using validation!
In this chapter, we are going to learn how programmers make sure the data entering a system is accurate and sensible. This is a vital part of the Testing phase in the Program Development Life Cycle. After all, if a user enters "Garbage" into a system, they will get "Garbage" back out!
1. Validation: "Is it sensible?"
Validation is an automatic check carried out by the computer when data is entered. Its goal is to ensure the data is reasonable and follows certain rules. It does not check if the data is 100% correct, only that it is possible.
According to your syllabus, there are six specific validation checks you need to know:
A. Range Check
Checks whether a number falls within a specified high and low limit.
Example: If you are entering a percentage for an exam, the range check would ensure the number is between \(0\) and \(100\).
B. Length Check
Checks that the data entered contains a specific number of characters or stays within a certain limit.
Example: A password must be at least \(8\) characters long, or a standard UK postcode must be between \(6\) and \(8\) characters.
C. Type Check
Checks that the data entered is of a specific data type (e.g., Integer, Real, or String).
Example: A "Number of Tickets" field should only accept integers (numbers like \(2\) or \(5\)), not letters like "Five".
D. Presence Check
Checks that a field has not been left blank. Some data is so important that the computer won't let you continue without it.
Example: An "Email Address" field on a contact form often has a presence check.
E. Format Check
Checks that the data follows a specific pattern of characters.
Example: A car license plate might need to follow the format: 2 letters, 2 numbers, a space, and then 3 letters (e.g., \(AB12\ XYZ\)).
F. Check Digit
This is a special digit calculated from the other digits in a number. It is used to spot errors in data entry (like typing a number wrong or swapping two digits).
Example: The last digit of an ISBN (found on books) or a Barcode is a check digit.
Quick Summary: Validation is automatic and checks if data is reasonable.
2. Verification: "Is it what you meant to type?"
Even if data passes all validation checks, it could still be wrong! For example, if you are \(15\) years old but accidentally type \(51\), a Range Check will accept it because \(51\) is a sensible age. This is where Verification comes in.
Verification is checking that the data entered matches the original source exactly. There are two main ways to do this:
Visual Check
The user looks at the data they have entered on the screen and compares it to the original document or their own memory to see if they made a mistake. They then confirm "Yes" or "No" that it is correct.
Double Entry
The data is entered twice, often into two different boxes. The computer compares the two entries. If they don't match exactly, the computer asks the user to type it again.
Example: When you create a new password, you are almost always asked to "Confirm Password" by typing it a second time.
Key Takeaway: Validation is done by the computer; Verification often involves the user ensuring the data is accurate.
3. Test Data
When you write a program, you have to prove that your validation and logic actually work. To do this, you use Test Data. There are four categories of test data you must use for a full "dry run" of your code:
1. Normal Data
Data that is acceptable and should be processed without any errors.
Example: If a range check allows numbers from \(1\) to \(10\), normal data would be \(5\).
2. Abnormal Data
Data that is the wrong type or outside the limits and should be rejected by the program.
Example: Using the \(1\) to \(10\) range again, abnormal data would be \("Ten"\) (wrong type) or \(25\) (outside range).
3. Extreme Data
These are the largest and smallest acceptable values. They are "at the edges" but should still be accepted.
Example: In the range \(1\) to \(10\), the extreme data values are \(1\) and \(10\).
4. Boundary Data
Boundary data is a pair of values at the limit of the range: one is accepted and the other is rejected.
Example: For the range \(1\) to \(10\), you would test the pairs \(0, 1\) (rejected/accepted) and \(10, 11\) (accepted/rejected).
Don't worry if Extreme and Boundary seem similar! Just remember: Extreme is only the values that are allowed (the very edges), while Boundary tests the transition from allowed to rejected.
4. Common Mistakes to Avoid
Mixing up Validation and Verification: Remember the "V"s!
Validation = Very sensible (Is it reasonable?)
Verification = Very same (Does it match the source?)
Forgetting the Check Digit: Students often forget that a Check Digit is a type of Validation, not Verification, because the computer calculates it automatically using an algorithm.
Confusing Extreme and Boundary:
If a range is \(1\) to \(100\):
Extreme: \(1\) and \(100\).
Boundary: \(0\) (rejected) and \(1\) (accepted) OR \(100\) (accepted) and \(101\) (rejected).
Final Review Checklist
Before you move on to Trace Tables or Writing Algorithms, make sure you can:
- Identify the 6 types of validation and give an example for each.
- Explain the 2 types of verification.
- Choose Normal, Abnormal, Extreme, and Boundary test data for a given scenario.
- Explain why we need validation (to prevent "Garbage In, Garbage Out").