Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Test data: normal, edge and wrong

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

Break the form

A college form asks for your age. It says: only 16, 17, 18 or 19.

You are the tester. What do you type to find a bug? Try 17. Try 16. Try 20. Try the word "abc".

A good tester picks data on purpose. Today you learn how.

Key words

WordWhat it meansExample
Test dataThe values we give to a program to test it.17
RangeThe values that are allowed, from a lowest to a highest. The lowest and the highest are the edges of the range.16 to 19
Valid dataData the program should accept.17
Invalid dataData of the right type that the program should refuse, because it is outside the range.5
Valid extreme dataData on the very edge of the range, still allowed.16 and 19
Invalid extreme dataData just outside the edge of the range, not allowed.15 and 20
Erroneous dataData of the wrong type. It is not the kind of thing the program expects, such as a word where a number should be."abc"
Expected resultWhat the program should do with that data.Accept, or show an error

The cells students fill in are left blank in this preview.

Five kinds of test data

KindExample for age 16 to 19Expected result
Valid (normal)17, 18Accepted
Valid extreme16, 19Accepted
Invalid5, 80Refused: outside the range
Invalid extreme15, 20Refused: outside the range
Erroneous"abc", empty, 16.5Refused: not a whole number

The cells students fill in are left blank in this preview.

The age range on a line

515161718192080
InvalidInvalid extremeValid extremeValid (normal)Valid (normal)Valid extremeInvalid extremeInvalid

The cells students fill in are left blank in this preview.

Why test the edges?

data-callouts.important.label

Programmers write age >= 16 and age <= 19. Here >= means "bigger than or equal to" and <= means "smaller than or equal to". A small mistake, such as age > 16 (only bigger than 16), refuses a 16 year old. Only the edge value 16 finds this. Testing 17 or 18 never shows the bug.

Try it: run the test data

Code: python
def check_age(text):
    if not text.isdigit():
        return "not a number"
    age = int(text)
    if age < 16 or age > 19:
        return "wrong range"
    return "ok"

for value in ["17", "16", "19", "15", "20", "abc", "16.5"]:
    print(value, "->", check_age(value))

# Change age < 16 to age <= 16. Which test data finds the bug?
# (<= means "smaller than or equal to")

Worked example: a test mark

KindA mark from 0 to 100Expected result
Valid55, 80Accepted
Valid extreme0, 100Accepted
Invalid-30, 400Refused
Invalid extreme-1, 101Refused
Erroneous"fifty", emptyRefused: not a number

The cells students fill in are left blank in this preview.

Four simple steps

For any range, follow four steps.

  1. Write the lowest and the highest allowed value.
  2. Valid extreme: those two values.
  3. Invalid extreme: one less than the lowest, one more than the highest.
  4. Add a normal value in the middle, and some wrong types.

The lesson goes on

2 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.