This set covers the whole validation, verification and testing module: choosing validation checks, telling validation from verification, designing test data, predicting results by tracing and finding untested branches. All scenarios are fictional.
Questions run from easy to harder. Write your answer first, then open the working. The restricted pseudocode trace trainer helps with the tracing questions, and the mistake log and retest queue is the place to record slips.
Questions
1. A form says: “A username must have 6 to 12 characters.” Name the validation check.
Show answer
A length check. It counts the characters, with a minimum of 6 and a maximum of 12.
2. A website asks the user to type their email address twice and compares the two. Is this validation or verification? Name the method.
Show answer
Verification, by double entry. The program compares two copies to confirm the user typed what they meant.
3. A product code must be three letters followed by two digits, such as ABC12. Name the check. Does XYZ99 pass? Does AB123 pass?
Show answer
A format check. XYZ99 passes because it is three letters then two digits. AB123 fails because it is two letters then three digits.
4. A range check accepts ages 13 to 17. A member’s true age is 15 but 14 is typed. Is it accepted? What could catch the mistake?
Show answer
Yes, 14 is accepted, because 13 <= 14 <= 17. Validation cannot know the true age. Verification, such as double entry or a visual check against the source, could catch it.
5. A rule says: “Percentage must be a whole number from 0 to 100 inclusive.” Complete a test table with normal, boundary and invalid data and the expected result for each.
Show answer
| Type | Test value | Expected result |
|---|---|---|
| Normal | 55 | Accepted |
| Boundary | 0 | Accepted |
| Boundary | 100 | Accepted |
| Boundary, just outside | -1 | Rejected |
| Boundary, just outside | 101 | Rejected |
| Invalid | “fifty” | Rejected |
6. Trace this algorithm and state the output.
X ← 3
Y ← 0
WHILE X > 0
Y ← Y + X
X ← X - 1
ENDWHILE
OUTPUT Y
Show answer
| Loop | X before | Y after | X after |
|---|---|---|---|
| 1 | 3 | 3 | 2 |
| 2 | 2 | 5 | 1 |
| 3 | 1 | 6 | 0 |
Now X > 0 is FALSE and the loop ends. The output is 6.
7. This code should accept percentages 0 to 100 inclusive. Which test values from question 5 make it fail, and why?
INPUT Percent
IF Percent > 0 AND Percent < 100 THEN
OUTPUT "Accepted"
ELSE
OUTPUT "Rejected"
ENDIF
Show answer
0 and 100 fail. Expected Accepted, but 0 > 0 is FALSE and 100 < 100 is FALSE, so the output is “Rejected”. The code should use >= and <=. The normal value 55 passes, which hides the fault.
8. Predict the output before running, using a trace table. The inputs are 5, 12, 10, 20.
Count ← 0
FOR I ← 1 TO 4
INPUT Value
IF Value > 10 THEN
Count ← Count + 1
ENDIF
NEXT I
OUTPUT Count
Show answer
| I | Value | Value > 10 | Count |
|---|---|---|---|
| 1 | 5 | FALSE | 0 |
| 2 | 12 | TRUE | 1 |
| 3 | 10 | FALSE | 1 |
| 4 | 20 | TRUE | 2 |
The output is 2. The value 10 is not greater than 10.
9. Predict the output for the inputs 150, -2, 40.
REPEAT
INPUT Mark
IF Mark < 0 OR Mark > 100 THEN
OUTPUT "Invalid"
ENDIF
UNTIL Mark >= 0 AND Mark <= 100
OUTPUT Mark
Show answer
150 > 100 so “Invalid” is output and the loop continues. -2 < 0 so “Invalid” is output again. 40 passes both checks, so the loop ends and 40 is output. The full output is: Invalid, Invalid, 40.
10. A ticket program gives price 5 for age under 12, price 10 for ages 12 to 59 and price 7 for 60 and over. Tests so far use ages 8 and 30. Which branch is untested, and what test would you add?
INPUT Age
IF Age < 12 THEN
Price ← 5
ELSE
IF Age < 60 THEN
Price ← 10
ELSE
Price ← 7
ENDIF
ENDIF
OUTPUT Price
Show answer
Age 8 reaches the first branch (price 5). Age 30 reaches the second (price 10). The ELSE branch for ages 60 and over is untested. Add Age = 60, expected price 7. Boundary tests 11, 12, 59 and 60 should give 5, 10, 10 and 7.
11. Write pseudocode that asks for a password until it has at least 8 characters. Then say what must also happen to verify it.
Show answer
REPEAT
INPUT Password
IF LENGTH(Password) < 8 THEN
OUTPUT "At least 8 characters needed"
ENDIF
UNTIL LENGTH(Password) >= 8
This is a length check, so it is validation. To verify, the user types the password a second time and the program compares the two entries. If they differ, it asks again.
If you got these wrong
| Slip | Go to |
|---|---|
| Named the wrong check, or confused range and length | Choosing a validation rule |
| Wrote that validation makes data correct | Verification and validation |
| Missed a boundary or chose only normal data | Designing test data |
| Trace table gave the wrong output | Explaining an expected result |
| Said a program was tested when a branch was never run | Identifying an untested branch |
Log each slip in the mistake log and retest queue and retry the question after a few days. If one error type keeps returning, that is a good topic to bring to online one-to-one Computer Science tuition.