πŸ“š Knowledge Library β€” Topic 7.7 β€” Algorithm Design & Problem Solving

Validation, Verification & Test Data

Learn how programs check that input is sensible, confirm that data was entered accurately and use different test data to check expected behaviour.

1. Invitation

Good programs do not trust every input automatically.

Users can enter the wrong type of data, leave a field empty or make a typing mistake.

Validation, verification and test data help programmers detect these problems.

πŸ’‘ Key idea: validation checks sensibility, verification checks accuracy, and test data checks behaviour.
Figure 1.1
Three Different Jobs
Sensible?
↓
Entered accurately?
↓
Program works?
2. Big Idea

Validation and verification are not the same.

Validation

Checks whether data is sensible, reasonable and in the expected form.

Example: an age must be between 0 and 120.

Verification

Checks whether data has been entered or copied accurately from the original source.

Example: enter a password twice and compare both entries.

πŸ’‘ Valid does not always mean correct. An age of 25 is sensible, but it could still be the wrong person's age.
3. FutureLogic Bridge

Think of a nightclub door.

The door staff first check whether your age is sensible for entry. That is like validation.

They then compare your face with the photograph on your ID. That is like verification.

πŸ’‘ Bridge: validation asks β€œIs this believable?” Verification asks β€œDoes it match the original?”
Figure 3.1
The Door-Check Bridge
Age acceptable?
↓
ID matches person?
↓
Entry allowed
4. Validation Checks

Different checks test different rules.

Range check

Checks that a value lies between an allowed minimum and maximum.

Type check

Checks that data has the required data type, such as an integer.

Length check

Checks that data contains the required number of characters.

Presence check

Checks that data has been entered and the field is not empty.

Format check

Checks that data follows a required pattern, such as an email containing @.

Check digit

Uses a calculation to detect errors in codes such as barcodes.

5. Validation in Pseudocode

Invalid data should be rejected and entered again.

A validation check normally needs repetition so the program keeps asking until valid data is entered.

ExampleRange check
REPEAT
  OUTPUT "Enter a mark from 0 to 100"
  INPUT Mark
UNTIL Mark >= 0 AND Mark <= 100
🎯 Exam Tip: checking once is not enough if the question says re-entry is required.
Figure 5.1
Validation Loop
Input
↓
Check rule
↓
Invalid? Re-enter
β†Ί
6. Verification Methods

Verification checks that data matches the source.

Double entry asks the user to enter the same data twice. The program compares both entries.

A visual check asks a person to compare the entered data with the original document.

πŸ’‘ Verification checks transcription accuracy, not whether the value is reasonable.
Figure 6.1
Two Verification Methods
Double entry
or
Visual comparison
7. What Is Test Data?

Test data checks how the program behaves.

Test data is deliberately chosen input used to check whether a program accepts valid data, rejects invalid data and produces the expected result.

Different types of test data explore different parts of the allowed range.

πŸ’‘ Testing should include accepted values and rejected values.
Figure 7.1
Test the Rules
Choose data
↓
Run program
↓
Compare result
↓
Find errors
8. Four Types of Test Data

Each type has a different purpose.

Normal

Clearly valid data that should be accepted.

Example: 50

Abnormal

Invalid data that should be rejected.

Example: 150

Extreme

The highest or lowest accepted value.

Example: 0 or 100

Boundary

Values on and just outside an acceptance limit.

Example: -1, 0, 100, 101
9. Extreme vs Boundary

These two are often confused.

Extreme data is at the limit of what is accepted.

Boundary data tests both sides of the limit: one value that should be accepted and a neighbouring value that should be rejected.

⚠️ Common Mistake: saying an extreme value is β€œvery large.” Extreme means an accepted limit, not simply a big number.
Figure 9.1
Range 1 to 80
Boundary: 0, 1
Extreme: 1

Extreme: 80
Boundary: 80, 81
10. Computational Thinking

Testing requires careful, systematic thinking.

SkillHow it appears
DecompositionEach input rule is tested separately.
Pattern recognitionRepeated failures may reveal the same logic error.
AbstractionFocus remains on the rules that matter.
Algorithmic thinkingTests are planned and carried out in a logical order.
πŸ’‘ Good testing is planned, not random.
Figure 10.1
Systematic Testing
Identify rule
↓
Choose test data
↓
Predict result
↓
Compare
11. Worked Example

Test a program that accepts marks from 0 to 100.

Test valueTypeExpected result
55NormalAccepted
0 and 100ExtremeAccepted
-1, 0, 100 and 101Boundary-1 and 101 rejected; 0 and 100 accepted
150AbnormalRejected

Exam-style explanation

β€œNormal data checks that a typical valid value is accepted. Extreme data checks the accepted limits. Boundary data checks values on and just outside each limit. Abnormal data checks that invalid values are rejected.”
12. Exam Tip

Always connect the test value to its purpose.

Do not write only the type name. Give the actual value and explain what the program should do with it.

🎯 Strong answer: β€œ101 is boundary data because it is just above the maximum accepted value of 100 and should be rejected.”
Figure 12.1
Complete Test Answer
Value
+
Type
+
Purpose
+
Expected result
13. Common Mistake

Validation does not prove that data is true.

A range check might accept an age of 25 because it is sensible.

It cannot know whether the user is actually 25.

⚠️ Correct answer: validation checks reasonableness, not accuracy or truth.
Figure 13.1
Sensible Is Not Certain
Age = 25
↓
Valid value

But possibly incorrect
14. Summary

Validation, verification and test data in one screen.

Validation checks that data is sensible and follows the required rules.

Verification checks that data matches the original source or repeated entry.

Normal, abnormal, extreme and boundary data are used to check whether the program behaves correctly.

πŸ’‘ Final thought: sensible, accurate and thoroughly tested are three different goals.
Figure 14.1
Final Model
Validate
↓
Verify
↓
Test
↓
Improve