AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Test it properly

Week 12 · 1.8 Testing · 3 lessons
1

Four kinds of data

Computing 9: Topic 1.8, pp. 135–154
GoalChoose normal, invalid and extreme test data for a program that accepts a range of values, and say how boundary data differs.
New words
normal data · data the program should accept; it is inside the allowed rangeinvalid data · data the program should reject; it is outside the allowed rangeextreme data · the smallest and the largest values that are still acceptedboundary data · the extreme values and the first rejected value on each side of the range
Explanation

Testing means running a program with chosen data and checking that the result is what the program should do. Good testing uses different kinds of data. Normal data is accepted and sits inside the allowed range. Invalid data is rejected, so it lies outside the range. Extreme data is valid, but it sits right on the edge: it is the smallest and the largest value that is still accepted. Boundary data is similar, but it adds the nearest rejected value on each side of the range. Some values are more than one kind. For example, the smallest accepted value is normal, extreme and boundary. Not every program has every kind of test data. A program with no range, or with only two choices, may have no extreme data.

Allowed range 1 to 36Values
Invalid (too low)… −5 0
Extreme and normal1
Normal2 … 35
Extreme and normal36
Invalid (too high)37 100 …
Worked examples
Python
1locker = int(input("Locker number? "))
2if locker >= 1 and locker <= 36:
3    print("Locker found")
4else:
5    print("No such locker")
Output
Locker found
A program for lockers. A school has lockers numbered 1 to 36, and the program accepts a number only if it is from 1 to 36 inclusive, which means that 1 and 36 are allowed. The user types 12, so the program prints Locker found. The user types 37, so it prints No such locker.
KindMeaningExamples for lockers 1 to 36
Normalaccepted5, 12, 30
Invalidrejected0, 37, −5, 100
Extremesmallest and largest accepted1 and 36
Boundaryextreme values and the first rejected value on each side0, 1, 36 and 37
The kinds of test data for the locker program. Normal data can be any accepted number. Invalid data can be any rejected number, and you choose a few. The extreme data is 1 and 36. The boundary data is 0, 1, 36 and 37: the extreme values and the rejected values next to them.
ValueNormalInvalidExtremeBoundary
−1noyesnoyes
0yesnoyesyes
2yesnonono
3yesnoyesyes
4noyesnoyes
9noyesnono
One value can be several kinds. A pizza maker allows 0 to 3 extra toppings. Each row names a value. The value 0 is accepted, so it is normal, and it is also extreme and on the boundary. The value 2 is only normal. The value −1 is invalid, and it is on the boundary because it is the first rejected value. The value 9 is only invalid.
Class activity

Secret range (no computer). Think of a secret whole-number range, such as ‘accepts numbers from 8 to 20’, and write it on a card that you hide. Your partner names a number, and you reply ‘accepted’ or ‘rejected’. Your partner writes down a list of normal, invalid and extreme test numbers from your replies, and tries to guess your range using as few questions as possible. Then show the card. Which questions told your partner the most: the normal numbers or the numbers next to the edges?

Practice
1
A program accepts a seat row from 1 to 20 inclusive. Give two normal values, two invalid values, the extreme values and the boundary values.
2
A game accepts 2 to 6 players, inclusive. Say whether each value is normal, invalid or extreme. Some values are two kinds.
ValueKind(s)
2?
4?
1?
6?
7?
3
A learner tests the locker program only with 3, 4 and 5. Why is this not enough?
4
A program asks the user to type A, B or C to choose a snack. Which kinds of test data can be used, and which cannot? Give examples.