import pytest
# Function with multiple conditions to test
def check_conditions(a: bool, b: bool) -> str:
if a and b:
return "Both True"
elif a and not b:
return "A True, B False"
elif not a and b:
return "A False, B True"
else:
return "Both False"
# Parameterized test to cover all condition combinations
@pytest.mark.parametrize("a,b,expected", [
(True, True, "Both True"),
(True, False, "A True, B False"),
(False, True, "A False, B True"),
(False, False, "Both False")
])
def test_check_conditions(a, b, expected):
result = check_conditions(a, b)
assert result == expected, f"Expected {expected} but got {result}"
The function check_conditions has two boolean inputs and multiple conditions combined with and and not. To achieve condition coverage, we must test all possible True/False values for each condition.
The test uses pytest.mark.parametrize to run the test function four times with all combinations of a and b. Each test asserts the function returns the expected string for that input.
This ensures each condition (a and b) is evaluated as True and False at least once, fulfilling condition coverage requirements.