Privacy Notice: When you sign in with GitHub, your quiz attempts are stored in Google Firebase so you can track your progress. This data is only accessible to the course instructor, is not otherwise shared, and will be deleted at the end of the semester. For earlier deletion, contact the instructor. Prefer to stay anonymous? Use guest mode or a GitHub account without your real name.
Loading...

03 Quiz: Coverage Concepts

Score: 0 / 20

Instructions

This quiz tests your understanding of code coverage concepts from Lectures 6 and 7.


Preparation: Read First

Before attempting this quiz, study the following lecture sections:

From Chapter 03 (TDD and CI): TDD and CI:

From Chapter 03 (Testing Theory and Coverage): Testing Theory & Coverage:


Why Take This Quiz?

For Your Learning:

  • Self-Assessment: Identify areas where you have strong understanding and topics that need review
  • Exam Preparation: The quiz format and difficulty mirror what you can expect in the final exam
  • Immediate Feedback: Get instant feedback on your answers to reinforce correct understanding
  • Active Recall: Testing yourself is one of the most effective learning techniques

Guidelines:

  • Each question has 4 options with exactly one correct answer
  • Try to answer without referring to the lecture materials first
  • Sign in with GitHub to save your progress across sessions
  • Or continue as guest (progress won’t be saved)

Scoring Guide

  • 18-20 correct: Excellent! Strong grasp of coverage concepts
  • 15-17 correct: Good understanding! Review the areas you missed
  • 12-14 correct: Fair understanding. Revisit the lecture materials
  • 9-11 correct: Review needed. Focus on fundamentals
  • Below 9: Please review Lectures 6 and 7 carefully
Question1 Definitions and Basics

Statement coverage (C0) measures:

Question2 Definitions and Basics

Branch coverage (C1) measures:

Question3 Definitions and Basics

A coverage criterion is:

Question4 Definitions and Basics

When we say “C1 subsumes C0,” we mean:

Question5 Definitions and Basics

A test suite is “adequate” according to a coverage criterion when:

Question6 Understanding and Calculation

Consider this code:

def check(value):
    if value > 0:
        return "positive"
    else:
        return "negative"

Why does achieving 100% C1 automatically give 100% C0?

Question7 Understanding and Calculation

Given this code and test:

def categorize(score):
    if score >= 90:
        return "A"
    elif score >= 80:
        return "B"
    elif score >= 70:
        return "C"
    else:
        return "F"

# Test:
def test_high_score():
    assert categorize(95) == "A"

What is the statement coverage (C0)?

Question8 Understanding and Calculation

Using the same categorize code with these tests:

def test_scores():
    assert categorize(95) == "A"
    assert categorize(85) == "B"

What is the branch coverage (C1)?

Question9 Understanding and Calculation

Given this pytest-cov output:

Name              Stmts   Miss  Cover   Missing
-----------------------------------------------
src/utils.py         24      6    75%   18-20, 35-37
-----------------------------------------------

What does “Missing: 18-20, 35-37” tell you?

Question10 Understanding and Calculation

Given this code (with line numbers):

1: def validate(value):
2:     if value is None:
3:         return "Error"
4:     if value < 0:
5:         return "Negative"
6:     if value == 0:
7:         return "Zero"
8:     return "Positive"

And this coverage report: Missing: 3, 7

Which conditions were NEVER True during testing?

Question11 Limitations of Coverage

A test suite achieves 100% statement coverage. This means:

Question12 Limitations of Coverage

Consider this test:

def calculate_total(items, discount_percent):
    total = sum(items)
    if discount_percent > 0:
        discount = total * (discount_percent / 100)
        total = total - discount
    return total

def test_calculate_total():
    result = calculate_total([10, 20, 30], 10)
    assert result > 0  # What's wrong?

What’s the problem with this test?

Question13 Limitations of Coverage

Which of the following bugs would 100% statement coverage likely MISS?

Question14 Limitations of Coverage

In which situation might 70% coverage be perfectly acceptable?

Question15 Limitations of Coverage

Which statement best describes the relationship between coverage and correctness?

Question16 Application

Given this code (with line numbers):

1: def classify_age(age):
2:     if age < 0:
3:         return "Invalid"
4:     elif age < 18:
5:         return "Minor"
6:     elif age < 65:
7:         return "Adult"
8:     else:
9:         return "Senior"

Your coverage report shows Line 9 is missing. Which test would cover it?

Question17 Application

Given this code and coverage report:

1: def calculate_shipping(weight, express=False):
2:     if weight <= 0:
3:         raise ValueError("Invalid")
4:
5:     base_cost = weight * 2.0
6:
7:     if express:
8:         return base_cost * 1.5
9:     return base_cost

Coverage report: Missing lines 3, 8

To cover BOTH missing lines, you need tests with which inputs?

Question18 Application

Given this pytest-cov output with branch coverage enabled:

Name              Stmts   Miss Branch BrPart  Cover
----------------------------------------------------
src/validator.py     20      2     10      3    82%
----------------------------------------------------

What does “BrPart: 3” indicate?

Question19 Application

Your team is setting up a CI pipeline for a financial transaction system. What coverage threshold is most appropriate?

Question20 Application

Why integrate coverage checks into a CI/CD pipeline?

© 2026 Dominik Mueller   •  Powered by Soopr   •  Theme  Moonwalk