0
0
Testing Fundamentalstesting~20 mins

Path coverage in Testing Fundamentals - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Path Coverage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Path Coverage Basics

Consider a simple function with two if statements in sequence. How many unique execution paths should be tested to achieve 100% path coverage?

Testing Fundamentals
def example(x, y):
    if x > 0:
        print("X positive")
    if y > 0:
        print("Y positive")
A4
B3
C2
D5
Attempts:
2 left
💡 Hint

Each if statement can be true or false independently.

Predict Output
intermediate
1:30remaining
Output of Path Coverage Example

What is the output when calling test_func(3, -1)?

Testing Fundamentals
def test_func(a, b):
    if a > 0:
        print("A positive")
    else:
        print("A non-positive")
    if b > 0:
        print("B positive")
    else:
        print("B non-positive")

# Call: test_func(3, -1)
AA positive\nB positive
BA non-positive\nB positive
CA positive\nB non-positive
DA non-positive\nB non-positive
Attempts:
2 left
💡 Hint

Check each if condition with the given inputs.

assertion
advanced
2:00remaining
Assertion for Full Path Coverage

Which assertion best verifies that all paths in the following function have been executed at least once?

Testing Fundamentals
def check_values(x, y):
    if x > 10:
        if y < 5:
            return "Path 1"
        else:
            return "Path 2"
    else:
        return "Path 3"
Aassert results == ["Path 1", "Path 2", "Path 3"]
Bassert set(results) == {"Path 1", "Path 2", "Path 3"}
Cassert "Path 1" in results and "Path 2" in results
Dassert len(results) == 3
Attempts:
2 left
💡 Hint

All unique paths must be covered regardless of order.

🔧 Debug
advanced
2:00remaining
Identify Path Coverage Miscount

Given this code, a tester claims there are 3 paths. Is this correct? If not, what is the correct number of paths?

Testing Fundamentals
def sample(x, y):
    if x > 0:
        if y > 0:
            return 1
    return 0
ACorrect, there are 3 paths: both true, first true second false, first false
BIncorrect, there are 2 paths: both true and others combined
CIncorrect, there are 4 paths: all combinations of x and y conditions
DIncorrect, there is only 1 path because y is checked only if x > 0
Attempts:
2 left
💡 Hint

Consider when the second if is evaluated.

framework
expert
2:30remaining
Designing Tests for Full Path Coverage

You have a function with three nested if statements. How many test cases are needed to guarantee 100% path coverage?

Function structure:

if A:
    if B:
        if C:
            do X
        else:
            do Y
    else:
        do Z
else:
    do W
A8 test cases
B5 test cases
C6 test cases
D4 test cases
Attempts:
2 left
💡 Hint

Count unique paths from root to leaves in the nested if structure.