Testing: validation, verification and test data

IGCSE Computer Science · Algorithm Design and Problem-Solving

Validation and verification are not the same

validationan automatic check by the computer that the data entered is reasonable
verificationa check that the data entered matches the original source

The crucial point, and the one most often missed: validation cannot tell whether data is correct — only whether it is sensible.

A date of birth of $\text{14/03/2008}$ passes every validation check that could be written. It is still wrong if the person was born in $2009$. Only verification — comparing against the source document — catches that.

Validation checks

Verification methods

Note that double entry does not prove the data is correct either: someone can make the same mistake twice, or copy the same wrong source. It only catches typing slips.

The four types of test data

normalvalues inside the accepted range that the program should accept — for a mark out of 100: $45$
abnormal (erroneous)values the program should reject — $-5$, $150$, or the word "fifty"
extremethe largest and smallest values still accepted — $0$ and $100$
boundaryvalues on either side of each limit, one accepted and one rejected — $-1$ and $0$; $100$ and $101$

Extreme and boundary are the pair most often confused. Extreme data is a single value at each end. Boundary data comes in pairs straddling the limit, and each pair tests a different outcome.

Boundary testing matters because the commonest coding error is writing $>$ where $\geq$ was meant. That error is invisible to normal data and only shows up exactly at the limit.

Trace tables

A trace table records the value of every variable after each step of an algorithm, so the programmer can see where a value first becomes wrong.

It is the standard way to dry-run an algorithm by hand, before or instead of running it.

Types of error

Logic errors are far more dangerous, precisely because nothing reports them.

Four types of test data — the valid mark range is 0 to 100 0 100 ACCEPTED RANGE rejected rejected NORMAL 45 ABNORMAL −5 ABNORMAL 150 EXTREME = one value at EACH end, still accepted: 0 và 100 BOUNDARY = a PAIR either side of each limit: (−1 và 0), (100 và 101) Boundary testing catches writing > instead of ≥ — a fault that normal data NEVER reveals.
Extreme is one value at each end; boundary comes as a pair, one accepted and one rejected.

Worked example: validation or verification

A school enters students' dates of birth from birth certificates. (a) State the validation checks that could be used. (b) Explain why validation is still not enough. (c) State two ways to verify the data and their limitations.

Solution

(a) Validation checks that could be used.

(b) Why validation is still not enough.

Validation can only answer the question “is this data reasonable?” It can never answer the question “is this data correct?”

A concrete example. A staff member types $\text{14/03/2008}$ while the birth certificate says $\text{14/03/2009}$.

This value passes every check in part (a): correct format, month and day within range, all numbers, not empty. The computer has no way of knowing it is wrong.

The root reason: the computer cannot see the birth certificate. It only has what was typed in, so it can only check whether that is reasonable in itself.

To detect a discrepancy from the original, there must be a comparison with the original — and that is precisely verification.

(c) Two ways to verify and their limitations.

Method one — double entry. The data is typed in twice, usually by two people, and the computer compares the two versions. A difference means at least one version was mistyped, and the computer asks for re-entry.

Limitation: it does not prove the data is correct. Two people can make the same mistake, or both misread the same badly written digit on the paper. It also doubles the data-entry time.

Method two — visual check. A person reads the data on screen and compares each field with the original document.

Limitation: it depends on human concentration. When checking hundreds of similar records, the checker misses things — and the longer they check, the more they miss.

Conclusion: no check is absolutely guaranteed. The practical approach is to use both: validation blocks unreasonable data, verification catches copying mistakes.

Worked example: choosing the four types of test data

A program accepts only marks from $0$ to $100$. Give an example for each type of test data, state the expected result, and explain why boundary data catches a fault that normal data does not.

Solution

Normal data. Examples: $45$, $72$.

Expected result: the program accepts them and processes them normally.

Purpose: to check that the program does its main job correctly with ordinary input.

Abnormal data. Examples: $-5$, $150$, and the word “fifty”.

Expected result: the program rejects them and shows a clear error message.

Note the third example: it tests the type check, that is, whether the program copes when the user types letters into a numeric field. Many programs crash at exactly this point.

Extreme data. Examples: $0$ and $100$.

Expected result: the program accepts both.

These are the largest and smallest values that are still valid — one value at each end.

Boundary data. Examples: the pair $(-1, 0)$ and the pair $(100, 101)$.

Expected result: $-1$ is rejected but $0$ is accepted; $100$ is accepted but $101$ is rejected.

Note that boundary data comes as a pair, and each pair tests two opposite results sitting side by side.

Why boundary data catches a fault that normal data does not.

The most common programming error here is writing a greater-than sign when the intention was greater than or equal to.

Specifically. Suppose the programmer writes the acceptance condition as $\text{mark} > 0$ and $\text{mark} < 100$, when it should be $\text{mark} \ge 0$ and $\text{mark} \le 100$.

This faulty program works perfectly normally with $45$, with $72$, with every value in between. Nothing shows up at all.

It goes wrong at exactly two values: it rejects $0$ and rejects $100$, even though both are valid.

In other words, this fault only shows up right at the limit. Without boundary testing the fault slips into the product, and is only discovered when a real student scores exactly $0$ or exactly $100$.

Common mistake

Saying validation guarantees the data is correct. It never can. Validation can only answer the question “is this data reasonable?” — and that is the only question a computer can answer, because it cannot see the original. The decisive example: the date of birth $\text{14/03/2008}$ passes every format check, range check, type check and presence check — but is still wrong if the birth certificate says $2009$. Only verification, that is, comparison with the original, can catch it. And even that is not absolute: double entry only catches typing slips, because two people can make the same mistake. The second trap in the chapter: confusing extreme data with boundary data. Extreme data is a single value at each end and is still accepted ($0$ and $100$). Boundary data comes as a pair lying either side of a limit, one accepted and one rejected ($-1$ and $0$) — and only this pair can catch the mistake of writing a greater-than sign instead of greater than or equal to.

Key takeaway

Validation is the computer checking whether data is reasonable; verification checks whether data matches the original — and no check proves the data is absolutely correct. Six validation checks: range, length, type, presence, format, check digit. Four types of test data: normal (accepted), abnormal (rejected), extreme (one value at each end, still accepted), boundary (a pair either side of a limit). Boundary is the type that catches the error of writing a greater-than sign instead of greater than or equal to. A trace table shows at which step a value starts to go wrong. A syntax error stops translation; a logic error still runs but gives a wrong result — more dangerous because nothing warns you.

← Decomposition and design tools · All IGCSE Computer Science lessons · Practice IGCSE Computer Science questions (free, instant scoring) · Data types, variables and control structures →