About

5.2 Equivalence Partitioning

Theory: Equivalence Partitioning

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.

Tom yumGreen curryMassamanpartition 1partition 2partition 3
Each pot is a partition. One spoon (one test value) from each pot is enough.

The procedure, as the professor gave it:

  1. Start with all possible input values (infinitely many).
  2. Put them into a fixed space with a clear border.
  3. Inside, split them into groups that share the same characteristic. Each group is a partition.
  4. 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:

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…ExampleValid partitionsInvalid partitions
A range of valuesAge from 18 to 601 (inside the range)2 (below and above)
A specific valueExactly 6 digits1 (that value)2 (below and above)
A member of a setCommand is one of: check, deposit, pay, transfer1 (in the set)1 (not in the set)
A BooleanArea code present?11

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 conditionTypeWhat the partitions look like
Area code: present?Booleanblank, or 3 digits
Area code: valueRange200 to 999 is valid; below 200 and above 999 are invalid
PrefixRange3 digits, cannot start with 0 or 1 (so 200 to 999)
SuffixSpecific valueexactly 4 digits
Password: present?Booleangiven, or missing
Password: valueSpecific valueexactly 6 characters
CommandMember of a setcheck, 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 ↓
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 ↓
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 ↓
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 ↓
Solution

Password length is a specific value, so 1 valid + 2 invalid:

PartitionValid?Example
exactly 8 charactersvalidabcd1234
fewer than 8 charactersinvalidabc
more than 8 charactersinvalidabcd12345

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 ↓
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 present? (Boolean, 1 + 1): blank / 3 digits given.
  • 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 ↓
Solution

Apply the guideline to each condition:

ConditionTypeValidInvalid
Area code: present?Boolean11
Area code: valueRange12
PrefixRange12
SuffixSpecific value12
Password: present?Boolean11
Password: valueSpecific value12
CommandSet11
Total711

7 valid and 11 invalid partitions, 18 in all. Check: 7+11=187 + 11 = 18 ✓. Instead of infinitely many phone numbers, passwords and commands, the tester now reasons about 18 groups.