Theory: Decision Tables
Equivalence partitioning handles inputs one at a time. But many requirements are about combinations of inputs: if this and that, then do something. For those, the course’s next black box tool is the decision table.
What It Is, and When to Use It
Think of a shop’s delivery policy: if the customer has a member card and the order is over 500 baht, then delivery is free; otherwise delivery is charged. Requirements like this are if-then rules, and they are everywhere. A decision table writes such rules in a neat table, so that nothing is forgotten.
- It fits if-then logic very naturally, and if-then logic is everywhere in specifications.
- Some testing tools can turn a decision table into code automatically, which gives you automated testing.
- Basic requirement: the inputs are independent. One rule’s result does not change another.
The Parts of a Decision Table
| Part | Where | Meaning |
|---|
| Conditions C1…Ck | top rows | the inputs |
| Actions A1…Am | bottom rows | the outputs |
| Rules R1,R2,… | columns | one column = one rule: if these conditions, then these actions |
| Entries | cells | 1 = true, 0 = false, X = don’t care |
Here is the delivery policy as a decision table:
| R1 | R2 | R3 |
|---|
| C1: has a member card | 1 | 1 | 0 |
| C2: order over 500 baht | 1 | 0 | X |
| A1: free delivery | 1 | 0 | 0 |
| A2: charge delivery | 0 | 1 | 1 |
Read each column top to bottom as one sentence. R1: if member and over 500, then free delivery. R3: if not a member, then charge delivery, whatever the order total (that is what the X says).
It Is a Truth Table, Turned Sideways
The professor asked the class: does this look familiar? It should. A decision table is a truth table, transposed: the rows became columns. So the same problem appears as with brute force:
With K conditions, a full decision table has 2K rules.
- A text editor with 4 conditions (copy, paste, bold, underline): 24=16 rules.
- 10 conditions: 210=1,024 rules. The table explodes, just like exhaustive testing (2.1).
Making It Smaller: “Don’t Care”
Often a condition does not matter for a rule. Then we write X (don’t care). One column with an X replaces two columns, one with 1 and one with 0, so several rules merge into one and the table becomes much smaller. In the delivery table, R3 (C1 = 0, C2 = X) stands for two full rules, (0, 1) and (0, 0), which both charge delivery: the full table has 22=4 rules, the reduced one 3.
You can also use a K-map (from digital logic) to find the don’t cares systematically: neighbouring cells with the same action merge, exactly as rules merge.
Common mistake: using X just to make the table shorter. Mark a condition X only when changing it cannot change the rule’s action. If it can, you have merged two rules that behave differently, and the table no longer says what the specification says.
Five Properties to Remember
- The order of the conditions does not change the meaning of a rule.
- The order of the rules does not change the result.
- Once a rule matches and an action is chosen, no other rule needs to be checked.
- If one rule gives several actions, their order is not important.
- Rules are complete (every combination of inputs is covered by some rule) and consistent (the same inputs always give the same action).
Exam-style answer: A requirement has 5 conditions. How many rules does a full decision table have? How can you reduce them?
25=32 rules. Reduce them with don’t care (X) entries: when a condition does not affect a rule, write X and merge the columns. Build a cause-effect graph first (6.3), so you keep only the input combinations that matter.
Worked Examples
Exercise 1
How is a decision table related to a truth table?
Show solution ↓Hide solution ↑
Solution
A decision table is a truth table turned sideways (transposed): each row of the truth table becomes a column, a rule. So a full decision table with K conditions has the same number of rules as the truth table has rows, 2K.
Exercise 2
A requirement has 5 conditions. How many rules does a full decision table have? How can you reduce them?
Show solution ↓Hide solution ↑
Solution
Each condition is true or false, so
25=32 rules.32 rules. To reduce them, use don’t care (X) entries: wherever a condition cannot affect a rule’s action, write X and merge the two columns into one. Better still, draw a cause-effect graph first, so the table is built only from the input combinations that matter.
Exercise 3
A text editor has 4 Boolean conditions (copy, paste, bold, underline). How many rules does the full table have? How many with 10 conditions? What does this tell you?
Show solution ↓Hide solution ↑
Solution
- 4 conditions: 24= 16 rules.
- 10 conditions: 210= 1,024 rules.
Each extra condition doubles the table. Like brute force, the full table explodes, which is why we reduce it with don’t cares and cause-effect graphs.
Exercise 4
A cinema’s rule: a student with a valid student card gets a discount; anyone without a valid card pays full price, whether or not they are a student. Write the full decision table with conditions C1 (is a student) and C2 (has a valid card), then reduce it with X.
Show solution ↓Hide solution ↑
Solution
Full table (22=4 rules). Only a student who also has a valid card gets the discount:
| R1 | R2 | R3 | R4 |
|---|
| C1: is a student | 1 | 1 | 0 | 0 |
| C2: valid card | 1 | 0 | 1 | 0 |
| A1: discount | 1 | 0 | 0 | 0 |
| A2: full price | 0 | 1 | 1 | 1 |
Reduce. R2 and R4 both have C2 = 0 and the same action (full price); C1 does not matter there, so they merge into one rule with C1 = X. R3 (C1 = 0, C2 = 1) stays as it is: it differs from R2 in both conditions, so those two cannot merge.
| R1 | R2’ | R3 |
|---|
| C1: is a student | 1 | X | 0 |
| C2: valid card | 1 | 0 | 1 |
| A1: discount | 1 | 0 | 0 |
| A2: full price | 0 | 1 | 1 |
3 rules. Check completeness: (1,1) → R1, (1,0) and (0,0) → R2’, (0,1) → R3 ✓; every input matches exactly one rule.
(Merging R3 and R4 instead, as C1 = 0, C2 = X, and keeping R2 also gives 3 rules. Either reduction is correct, as long as every X is truly a don’t care.)
Exercise 5
Check this table against the five properties. Which properties does it break, and how would you show it with a test?
Show solution ↓Hide solution ↑
Solution
Go through all 22=4 input combinations:
| (C1, C2) | Matching rules | Actions |
|---|
| (1, 0) | R1 | A1 |
| (0, 1) | R2 | A2 |
| (1, 1) | R1 and R2 | A1 and A2 conflict |
| (0, 0) | none | no action |
- It is not consistent: input (1, 1) matches both rules, which give different actions.
- It is not complete: input (0, 0) matches no rule.
Tests that expose it: (1, 1), where the expected action is undefined, and (0, 0), where nothing is specified. A tester reports both as specification problems and asks what should happen.