Introduction
When testing software, it is important to check that every part of the code works correctly. One challenge is to make sure that all the different conditions in decisions are tested, so no hidden errors remain.
Imagine a security system with multiple sensors, like a door sensor and a window sensor. Condition coverage is like testing each sensor separately to make sure it triggers correctly when opened or closed.
┌───────────────────────────────┐ │ Decision (if) │ │ ┌───────────────┐ ┌───────────┐ │ │ │ Condition A │ │ Condition B│ │ │ └──────┬────────┘ └─────┬─────┘ │ │ │ │ │ │ True / False True / False│ └────────┴────────────────┴───────┘
def check_access(age, has_ticket): if age >= 18 and has_ticket: return "Access granted" else: return "Access denied" # Tests for condition coverage print(check_access(20, True)) # Both conditions true print(check_access(16, True)) # age false, has_ticket true print(check_access(20, False)) # age true, has_ticket false print(check_access(16, False)) # Both conditions false