A black box tester faces infinitely many possible inputs. You cannot try them all (2.1), so you need a principled way to pick a few that speak for the rest. The first tool for that is equivalence partitioning (EP).
The Idea in One Picture: Three Pots of Soup
Imagine you are the cook, and you have three pots of soup on the stove: tom yum, green curry and massaman. Do you need to drink a whole pot to know whether it is too salty? No. One spoon is enough, because every spoon from the same pot tastes the same. But one spoon from the tom yum tells you nothing about the green curry, so you taste one spoon from each pot.
EP works exactly the same way. Each pot is a group of inputs, and one test value tells you about its whole group.
Each pot is a partition. One spoon (one test value) from each pot is enough.
The procedure, as the professor gave it:
Start with all possible input values (infinitely many).
Put them into a fixed space with a clear border.
Inside, split them into groups that share the same characteristic. Each group is a partition.
Test one sample from each partition.
Why “Equivalence”?
All members of one partition are equivalent: the program treats them the same way. So one sample decides for the whole group:
If the sample passes, we assume the whole partition passes.
If the sample fails, we assume the whole partition fails.
Partitions are also called equivalence classes (EC). The two names mean the same thing.
Exam radar: EP turns an infinite number of input and output combinations into a small, finite number of partitions. EP is for outputs too, not only inputs. A partition the program should never produce is just as much a partition as one it should never accept.
The Four Guidelines
How many partitions do you need? It depends on the type of the input condition. The professor called this table very important:
If the input is…
Example
Valid partitions
Invalid partitions
A range of values
Age from 18 to 60
1 (inside the range)
2 (below and above)
A specific value
Exactly 6 digits
1 (that value)
2 (below and above)
A member of a set
Command is one of: check, deposit, pay, transfer
1 (in the set)
1 (not in the set)
A Boolean
Area code present?
1
1
Why is a set different from a range?
A range has an order, so a bad value can fall off either end: an age of 15 is below the range and 70 is above it, and a program can get the two ends wrong independently. A set has no “below” or “above”. A command is either in the list or it is not, so there is only one way to be wrong. A Boolean is the same: true or false.
In short: range or specific value → 1 valid + 2 invalid; set or Boolean → 1 valid + 1 invalid.
Example: An ATM
The professor’s first example is a (very old) banking system. Users connect with a phone number, give a 6-digit password, and type commands. Each input condition is classified by type, and the type tells you the partitions:
Input condition
Type
What the partitions look like
Area code: present?
Boolean
blank, or 3 digits
Area code: value
Range
200 to 999 is valid; below 200 and above 999 are invalid
Prefix
Range
3 digits, cannot start with 0 or 1 (so 200 to 999)
Suffix
Specific value
exactly 4 digits
Password: present?
Boolean
given, or missing
Password: value
Specific value
exactly 6 characters
Command
Member of a set
check, deposit, bill pay, transfer, …
Notice that the area code has two conditions. First, is it there at all, or blank (a Boolean)? Second, if it is there, is it in the allowed range (a range)? The same goes for the password. One input can carry more than one type of condition, and the tester must handle each of them.
Common mistake: giving one input field one partition rule. Ask of every input all the questions that apply: is it present (Boolean)? Is it in range (range)? Is it the right length (specific value)? Is it the right type (a letter where a number is expected is its own invalid partition, see 5.4)?
Worked Examples
Exercise 1
What is the main idea of equivalence partitioning?
Show solution ↓Hide solution ↑
Solution
Split the infinite inputs (and outputs) into a small number of partitions. All members of a partition are treated the same way by the program, so we test one sample from each partition: if it passes, we assume the whole partition passes; if it fails, we assume the whole partition fails.
Like tasting one spoon from each pot of soup: one spoon speaks for its whole pot.
Exercise 2
An input must be between 1 and 100. How many valid and invalid partitions are there? Name them.
Show solution ↓Hide solution ↑
Solution
The input is a range, so the guideline is 1 valid + 2 invalid:
valid: 1 to 100,
invalid: below 1,
invalid: above 100.
1 valid and 2 invalid partitions.
Exercise 3
An input must be one of red, green, blue. How many valid and invalid partitions are there? Why is this different from Exercise 2?
Show solution ↓Hide solution ↑
Solution
The input is a member of a set, so the guideline is 1 valid + 1 invalid:
valid: in the set (red, green or blue),
invalid: not in the set (for example purple).
1 valid and 1 invalid partition. A set has no order, so there is no “below” or “above”: a value is either in the list or not. A range has two ends, so it has two invalid partitions.
Exercise 4
A login form requires a password of exactly 8 characters, and a “remember me” checkbox that may be ticked or not. Using the four guidelines, list the partitions for each input.
Show solution ↓Hide solution ↑
Solution
Password length is a specific value, so 1 valid + 2 invalid:
Partition
Valid?
Example
exactly 8 characters
valid
abcd1234
fewer than 8 characters
invalid
abc
more than 8 characters
invalid
abcd12345
Remember me is a Boolean, so 1 + 1: ticked, and not ticked.
Here both Boolean values are allowed by the specification, so each is a behaviour to check (remembered vs. not remembered). The guideline still gives you the count: two partitions for the checkbox, three for the password length.
Exercise 5
In the ATM example, why does the area code need two separate input conditions? Write the partitions for both.
Show solution ↓Hide solution ↑
Solution
The area code can be left blank, and if it is given, it must be in range. Those are two different questions, of two different types, and a program can get each one wrong independently.
Area code value (range 200 to 999, 1 + 2): valid 200 to 999; invalid below 200; invalid above 999.
So the area code alone gives 5 partitions: 2 from the Boolean and 3 from the range.
Exercise 6
Count the valid and invalid partitions for the whole ATM input table (area code present, area code value, prefix, suffix, password present, password value, command).
Show solution ↓Hide solution ↑
Solution
Apply the guideline to each condition:
Condition
Type
Valid
Invalid
Area code: present?
Boolean
1
1
Area code: value
Range
1
2
Prefix
Range
1
2
Suffix
Specific value
1
2
Password: present?
Boolean
1
1
Password: value
Specific value
1
2
Command
Set
1
1
Total
7
11
7 valid and 11 invalid partitions, 18 in all. Check: 7+11=18 ✓. Instead of infinitely many phone numbers, passwords and commands, the tester now reasons about 18 groups.