Suggesting test data for length, presence and format checks

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Suggesting test data for length, presence and format checks

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A password must have at least 8 characters. What is the expected outcome for the test value Football (8 characters)?
A Rejected, because it is exactly 8 characters
B Accepted, because 8 characters meets the minimum
2. Which value is good test data for a password that is one character too short for the 8-character minimum?
A Penguin (7 characters)
B Penguins (8 characters)
3. Which value should a presence check on a username reject?
A An empty string
B A single letter such as a
4. Which test data best checks the edge of an 8-character minimum length check?
A Only a password with 30 characters
B A password with 8 characters and one with 7 characters
5. A format check requires a student ID of two letters then three digits, like AB123. Which value should be rejected?
A 12ABC, because the pattern is wrong
B QR482, because it has too many letters

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1LENGTH(Password) >= 8 AFormat: 2 letters then 3 digits -> "AB123" accepted, "1234A" rejected
2Password <> "" BThe rejected value is 9 characters, which is longer than the minimum, so it would actually pass. The failing value should be one character too short, such as "abcd123" with 7 characters.
3Test data for a length check of 8 characters minimum should include a value that is one character too short, which must be rejected. CA presence check. Test data: an empty string "" is rejected, and any entry such as "abcd1234" is accepted.
4Test data for a format check should include a value with the wrong pattern, such as a code with letters where digits are needed, which must be rejected. DThe outcomes are the wrong way round. The empty string should be rejected because nothing was entered, and "abcd1234" should be accepted because data is present.
5Length check (minimum 8): test data "abcd1234" accepted and "abcd12345" rejected EA length check for a minimum of 8 characters. Test data: "abcd1234" (8 characters) is accepted and "abcd123" (7 characters) is rejected.
6Presence check test data: "" accepted, "abcd1234" rejected FTest value "abcd123" -> LENGTH(Password) = 7 -> Rejected

Definitions

LENGTH(Password) >= 8

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF LENGTH(Password) >= _ THEN OUTPUT "Accepted" ENDIF
2.
IF LENGTH(Password) _ 8 THEN OUTPUT "Too short" ENDIF
3.
IF LENGTH(Password) = _ THEN OUTPUT "Please enter a password" ENDIF
4.
Password ← "abcdefg" Valid ← LENGTH(Password) >= 8 // Expected result: _____
5.
IF SUBSTRING(Code, _, 2) = "AB" THEN OUTPUT "Format OK" ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A IF LENGTH(Password) >= 8 THEN
B IF LENGTH(Password) > 8 THEN
C ENDIF
Question 2
A // Minimum length is 8
B // Test: 'abcdefgh' (8 chars)
C // Expected: accepted
D // Test: 'abcdefg' (8 chars)
E // Expected: rejected
Question 3
A IF Password <> "" THEN
B OUTPUT "Enter a password"
C ENDIF
Question 4
A Password ← ""
B IF LENGTH(Password) = 0 THEN
C OUTPUT "Accepted"
D ENDIF
Question 5
A // Format: 2 letters 3 digits
B ValidCode ← "A1B23"
C InvalidCode ← "1234A"
D // Expect: accepted, rejected

Answer Key

Suggesting test data for length, presence and format checks
Section A: Quick Questions
Q1
B — Accepted, because 8 characters meets the minimum
Q2
A — Penguin (7 characters)
Q3
A — An empty string
Q4
B — A password with 8 characters and one with 7 characters
Q5
A — 12ABC, because the pattern is wrong
Section B: Match the Pairs
Q1
LENGTH(Password) >= 8 → A length check for a minimum of 8 characters. Test data: "abcd1234" (8 characters) is accepted and "abcd123" (7 characters) is rejected.
Q2
Password <> "" → A presence check. Test data: an empty string "" is rejected, and any entry such as "abcd1234" is accepted.
Q3
Test data for a length check of 8 characters minimum should include a value that is one character too short, which must be rejected. → Test value "abcd123" -> LENGTH(Password) = 7 -> Rejected
Q4
Test data for a format check should include a value with the wrong pattern, such as a code with letters where digits are needed, which must be rejected. → Format: 2 letters then 3 digits -> "AB123" accepted, "1234A" rejected
Q5
Length check (minimum 8): test data "abcd1234" accepted and "abcd12345" rejected → The rejected value is 9 characters, which is longer than the minimum, so it would actually pass. The failing value should be one character too short, such as "abcd123" with 7 characters.
Q6
Presence check test data: "" accepted, "abcd1234" rejected → The outcomes are the wrong way round. The empty string should be rejected because nothing was entered, and "abcd1234" should be accepted because data is present.
Section C: Definitions
Q1
LENGTH(Password) >= 8 — Test data for a check includes values that pass and fail it: for an 8-character minimum, 8 characters is accepted, 7 is rejected, and an empty string fails a presence check.
Section D: Fill in the Blanks
Q1
IF LENGTH(Password) >= 8 THEN OUTPUT "Accepted" ENDIF
Q2
IF LENGTH(Password) < 8 THEN OUTPUT "Too short" ENDIF
Q3
IF LENGTH(Password) = 0 THEN OUTPUT "Please enter a password" ENDIF
Q4
Password ← "abcdefg" Valid ← LENGTH(Password) >= 8 // Expected result: FALSE
Q5
IF SUBSTRING(Code, 1, 2) = "AB" THEN OUTPUT "Format OK" ENDIF
Section E: Spot the Error
Q1
B — The minimum is 8 characters, so a password of exactly 8 must be accepted. > 8 would reject it. The condition should be >= 8.
Q2
D — 'abcdefg' has only 7 characters. It is the test value one character too short, so the comment should say (7 chars).
Q3
A — A presence check fails when nothing was entered, so the test must be for the empty string. It should be Password = "", not <>.
Q4
C — An empty string has length 0 and fails the presence check, so the expected outcome is Rejected, not Accepted.
Q5
B — The valid test value must match the format of 2 letters then 3 digits. "A1B23" has the wrong pattern. It should be "AB123".